summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 5210372)
raw | patch | inline | side by side (parent: 5210372)
author | Kay Sievers <kay.sievers@vrfy.org> | |
Thu, 5 May 2005 12:38:25 +0000 (14:38 +0200) | ||
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | |
Thu, 5 May 2005 15:23:01 +0000 (08:23 -0700) |
Allow to store and track symlink in the repository. A symlink is stored
the same way as a regular file, only with the appropriate mode bits set.
The symlink target is therefore stored in a blob object.
This will hopefully make our udev repository fully functional. :)
Signed-off-by: Kay Sievers <kay.sievers@vrfy.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
the same way as a regular file, only with the appropriate mode bits set.
The symlink target is therefore stored in a blob object.
This will hopefully make our udev repository fully functional. :)
Signed-off-by: Kay Sievers <kay.sievers@vrfy.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
cache.h | patch | blob | history | |
check-files.c | patch | blob | history | |
checkout-cache.c | patch | blob | history | |
diff-cache.c | patch | blob | history | |
ls-files.c | patch | blob | history | |
read-cache.c | patch | blob | history | |
update-cache.c | patch | blob | history |
index 8dd812827604d510038f5d93e3718c43f9d12c30..e6ce7312c1f84490e6e3518e9c71047cd2806d05 100644 (file)
--- a/cache.h
+++ b/cache.h
#define ce_stage(ce) ((CE_STAGEMASK & ntohs((ce)->ce_flags)) >> CE_STAGESHIFT)
#define ce_permissions(mode) (((mode) & 0100) ? 0755 : 0644)
-#define create_ce_mode(mode) htonl(S_IFREG | ce_permissions(mode))
+static inline unsigned int create_ce_mode(unsigned int mode)
+{
+ if (S_ISREG(mode))
+ return htonl(S_IFREG | ce_permissions(mode));
+ if (S_ISLNK(mode))
+ return htonl(S_IFLNK);
+ return htonl(mode);
+}
#define cache_entry_size(len) ((offsetof(struct cache_entry,name) + (len) + 8) & ~7)
#define MODE_CHANGED 0x0008
#define INODE_CHANGED 0x0010
#define DATA_CHANGED 0x0020
+#define TYPE_CHANGED 0x0040
/* Return a statically allocated filename matching the sha1 signature */
extern char *sha1_file_name(const unsigned char *sha1);
diff --git a/check-files.c b/check-files.c
index 7d16691aa9d51b5b4670d5837b3527ee7c7da79c..bfd5590e047a6ee0f7d9db956cc489ffc23dcd5a 100644 (file)
--- a/check-files.c
+++ b/check-files.c
die("preparing to update existing file '%s' not in cache", path);
ce = active_cache[pos];
- if (fstat(fd, &st) < 0)
- die("fstat(%s): %s", path, strerror(errno));
+ if (lstat(path, &st) < 0)
+ die("lstat(%s): %s", path, strerror(errno));
changed = cache_match_stat(ce, &st);
if (changed)
diff --git a/checkout-cache.c b/checkout-cache.c
index a1ef9448c35fa76ea036faae1a789f0cb654198d..367b9c7991f7e78954805e526d785b715446f1a9 100644 (file)
--- a/checkout-cache.c
+++ b/checkout-cache.c
unsigned long size;
long wrote;
char type[20];
+ char target[1024];
new = read_sha1_file(ce->sha1, type, &size);
if (!new || strcmp(type, "blob")) {
return error("checkout-cache: unable to read sha1 file of %s (%s)",
path, sha1_to_hex(ce->sha1));
}
- fd = create_file(path, ntohl(ce->ce_mode));
- if (fd < 0) {
+ switch (ntohl(ce->ce_mode) & S_IFMT) {
+ case S_IFREG:
+ fd = create_file(path, ntohl(ce->ce_mode));
+ if (fd < 0) {
+ free(new);
+ return error("checkout-cache: unable to create file %s (%s)",
+ path, strerror(errno));
+ }
+ wrote = write(fd, new, size);
+ close(fd);
+ free(new);
+ if (wrote != size)
+ return error("checkout-cache: unable to write file %s", path);
+ break;
+ case S_IFLNK:
+ memcpy(target, new, size);
+ target[size] = '\0';
+ if (symlink(target, path)) {
+ free(new);
+ return error("checkout-cache: unable to create symlink %s (%s)",
+ path, strerror(errno));
+ }
+ free(new);
+ break;
+ default:
free(new);
- return error("checkout-cache: unable to create %s (%s)",
- path, strerror(errno));
+ return error("checkout-cache: unknown file mode for %s", path);
}
- wrote = write(fd, new, size);
- close(fd);
- free(new);
- if (wrote != size)
- return error("checkout-cache: unable to write %s", path);
return 0;
}
memcpy(path, base_dir, len);
strcpy(path + len, ce->name);
- if (!stat(path, &st)) {
+ if (!lstat(path, &st)) {
unsigned changed = cache_match_stat(ce, &st);
if (!changed)
return 0;
diff --git a/diff-cache.c b/diff-cache.c
index 03dd69df3eb3bc9a516f3bec06a3580a78abf632..94c5f6654bdee04cf56adeb77b22ae998fdce678 100644 (file)
--- a/diff-cache.c
+++ b/diff-cache.c
static unsigned char no_sha1[20];
int changed;
struct stat st;
- if (stat(ce->name, &st) < 0)
+ if (lstat(ce->name, &st) < 0)
return -1;
changed = cache_match_stat(ce, &st);
if (changed) {
diff --git a/ls-files.c b/ls-files.c
index 8b53f2fd52fb3ff30393dac7d00707e76ad96aa4..58b5aee94ee76c9201c580d271fcb6aaf20d421f 100644 (file)
--- a/ls-files.c
+++ b/ls-files.c
struct stat st;
if (excluded(ce->name) != show_ignored)
continue;
- if (!stat(ce->name, &st))
+ if (!lstat(ce->name, &st))
continue;
printf("%s%c", ce->name, line_terminator);
}
diff --git a/read-cache.c b/read-cache.c
index 53f1da815bc2c23b25894663fa2cac17b08e64b2..5703f30b6a44c27a2ead3eb3a5ab17bcce670ad9 100644 (file)
--- a/read-cache.c
+++ b/read-cache.c
{
unsigned int changed = 0;
+ switch (ntohl(ce->ce_mode) & S_IFMT) {
+ case S_IFREG:
+ changed |= !S_ISREG(st->st_mode) ? TYPE_CHANGED : 0;
+ break;
+ case S_IFLNK:
+ changed |= !S_ISLNK(st->st_mode) ? TYPE_CHANGED : 0;
+ break;
+ default:
+ die("internal error: ce_mode is %o", ntohl(ce->ce_mode));
+ }
if (ce->ce_mtime.sec != htonl(st->st_mtime))
changed |= MTIME_CHANGED;
if (ce->ce_ctime.sec != htonl(st->st_ctime))
diff --git a/update-cache.c b/update-cache.c
index bb25fa114c1017380c8441f514ae2e66beef1e68..05d584ed48e8c7fbb200c4b9528481c1802c5bae 100644 (file)
--- a/update-cache.c
+++ b/update-cache.c
struct cache_entry *ce;
struct stat st;
int fd;
+ unsigned int len;
+ char target[1024];
- fd = open(path, O_RDONLY);
- if (fd < 0) {
+ if (lstat(path, &st) < 0) {
if (errno == ENOENT || errno == ENOTDIR) {
if (allow_remove)
return remove_file_from_cache(path);
}
return -1;
}
- if (fstat(fd, &st) < 0) {
- close(fd);
- return -1;
- }
namelen = strlen(path);
size = cache_entry_size(namelen);
ce = xmalloc(size);
fill_stat_cache_info(ce, &st);
ce->ce_mode = create_ce_mode(st.st_mode);
ce->ce_flags = htons(namelen);
-
- if (index_fd(ce->sha1, fd, &st) < 0)
+ switch (st.st_mode & S_IFMT) {
+ case S_IFREG:
+ fd = open(path, O_RDONLY);
+ if (fd < 0)
+ return -1;
+ if (index_fd(ce->sha1, fd, &st) < 0)
+ return -1;
+ break;
+ case S_IFLNK:
+ len = readlink(path, target, sizeof(target));
+ if (len == -1 || len+1 > sizeof(target))
+ return -1;
+ if (write_sha1_file(target, len, "blob", ce->sha1))
+ return -1;
+ break;
+ default:
return -1;
-
+ }
return add_cache_entry(ce, allow_add);
}
struct cache_entry *updated;
int changed, size;
- if (stat(ce->name, &st) < 0)
+ if (lstat(ce->name, &st) < 0)
return ERR_PTR(-errno);
changed = cache_match_stat(ce, &st);
return ce;
/*
- * If the mode has changed, there's no point in trying
+ * If the mode or type has changed, there's no point in trying
* to refresh the entry - it's not going to match
*/
- if (changed & MODE_CHANGED)
+ if (changed & (MODE_CHANGED | TYPE_CHANGED))
return ERR_PTR(-EINVAL);
if (compare_data(ce, st.st_size))