add conversion functions for fileindex/stat permission bits
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
diff --git a/lib/fileindex.c b/lib/fileindex.c
index f3934b9..54d3549 100644
--- a/lib/fileindex.c
+++ b/lib/fileindex.c
@@ -51,6 +51,20 @@ struct got_fileindex {
#define GOT_FILEIDX_MAX_ENTRIES INT_MAX
};
+uint16_t
+got_fileindex_perms_from_st(struct stat *sb)
+{
+ uint16_t perms = (sb->st_mode & (S_IRWXU | S_IRWXG | S_IRWXO));
+ return (perms << GOT_FILEIDX_MODE_PERMS_SHIFT);
+}
+
+mode_t
+got_fileindex_perms_to_st(struct got_fileindex_entry *ie)
+{
+ mode_t perms = (ie->mode >> GOT_FILEIDX_MODE_PERMS_SHIFT);
+ return (perms & (S_IRWXU | S_IRWXG | S_IRWXO));
+}
+
const struct got_error *
got_fileindex_entry_update(struct got_fileindex_entry *entry,
const char *ondisk_path, uint8_t *blob_sha1, uint8_t *commit_sha1,
@@ -82,8 +96,7 @@ got_fileindex_entry_update(struct got_fileindex_entry *entry,
entry->mode = GOT_FILEIDX_MODE_SYMLINK;
else
entry->mode = GOT_FILEIDX_MODE_REGULAR_FILE;
- entry->mode |= ((sb.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO)) <<
- GOT_FILEIDX_MODE_PERMS_SHIFT);
+ entry->mode |= got_fileindex_perms_from_st(&sb);
}
if (blob_sha1) {
diff --git a/lib/got_lib_fileindex.h b/lib/got_lib_fileindex.h
index c3528c7..3e7fc83 100644
--- a/lib/got_lib_fileindex.h
+++ b/lib/got_lib_fileindex.h
@@ -89,6 +89,9 @@ struct got_fileindex_hdr {
uint8_t sha1[SHA1_DIGEST_LENGTH]; /* checksum of above on-disk data */
};
+uint16_t got_fileindex_perms_from_st(struct stat *);
+mode_t got_fileindex_perms_to_st(struct got_fileindex_entry *);
+
const struct got_error *got_fileindex_entry_update(struct got_fileindex_entry *,
const char *, uint8_t *, uint8_t *, int);
const struct got_error *got_fileindex_entry_alloc(struct got_fileindex_entry **,
diff --git a/lib/worktree.c b/lib/worktree.c
index 08d2a40..5368b2c 100644
--- a/lib/worktree.c
+++ b/lib/worktree.c
@@ -1055,9 +1055,7 @@ get_file_status(unsigned char *status, struct stat *sb,
*status = GOT_STATUS_MISSING;
else
*status = GOT_STATUS_DELETE;
- sb->st_mode =
- ((ie->mode >> GOT_FILEIDX_MODE_PERMS_SHIFT)
- & (S_IRWXU | S_IRWXG | S_IRWXO));
+ sb->st_mode = got_fileindex_perms_to_st(ie);
} else
sb->st_mode = GOT_DEFAULT_FILE_MODE;
return NULL;