Skip to content

Commit

Permalink
Merge branch 'fixes'
Browse files Browse the repository at this point in the history
* fixes:
  bee-cache-inventory: get symlink destination with readlink() if missing
  manpages: Fix bee-update.1 manpage alias
  beelib: export BEE_BINDIR
  • Loading branch information
mariux committed Aug 13, 2012
2 parents e1a0957 + 4e35e34 commit 36f68c4
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
2 changes: 1 addition & 1 deletion manpages/bee-update.1.in
Original file line number Diff line number Diff line change
@@ -1 +1 @@
.so bee-install.1
.so man1/bee-install.1
37 changes: 34 additions & 3 deletions src/bee-cache-inventory.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ struct item {
char *type;
char *filename;
char *destination;
char free_destination;
};

struct inventory_meta {
Expand Down Expand Up @@ -146,6 +147,28 @@ int substitute(char *data, char from, char to)
return 1;
}

char *read_symlink(const char *filename)
{
ssize_t ret;
char buffer[PATH_MAX + 1] = {0};
char *copy;

ret = readlink(filename, buffer, PATH_MAX);

if (ret == -1) {
fprintf(stderr, "bee-cache-inventory: warning: "
"cannot restore empty symlink destination for file '%s': %m\n", filename);
return NULL;
}

copy = strdup(buffer);

if (!copy)
fprintf(stderr, "bee-cache-inventory: read_symlink: strdup: %m\n");

return copy;
}

BEE_STATIC_INLINE char *_extract_pattern(struct item *item, char **dest, char *hint, char *pattern, char size, int failok)
{
char *p;
Expand Down Expand Up @@ -182,12 +205,17 @@ int do_separation(char *line, struct item *item)
/* get possible symlink destination */
q = strstr(item->filename, "//");
if (q) {
*q = '\0';
item->destination = q + 2;

if (!*item->destination) {
fprintf (stderr, "bee-cache-inventory: syntax error: empty destination for file '%s'\n", item->filename);
return 0;
item->destination = read_symlink(item->filename);

if (!item->destination)
item->destination = item->filename;
else
item->free_destination = 1;
}
*q = '\0';
}

*(p-6) = 0;
Expand Down Expand Up @@ -344,6 +372,9 @@ int inventory_fhfh(FILE *infh, FILE *outfh, struct inventory_meta meta)

print_item(outfh, item, meta);

if (item.free_destination)
/* symlink destination was generated by read_symlink */
free(item.destination);
}

return 1;
Expand Down
1 change: 1 addition & 0 deletions src/beelib.config.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ function config_export() {
export BEE_TMP_TMPDIR
export BEE_TMP_BUILDROOT

export BEE_BINDIR
export BEE_SYSCONFDIR
export BEE_DATADIR
export BEE_LIBEXECDIR
Expand Down

0 comments on commit 36f68c4

Please sign in to comment.