Skip to content

Commit

Permalink
regression: fix hardlink creation
Browse files Browse the repository at this point in the history
When looking up for a file to hardlink from, it may have been itself
extracted in a temporary directory, so lookup for it.

While here create the missing directories for the target path if needed
  • Loading branch information
bapt committed Aug 4, 2022
1 parent 36b275f commit 0a8b8a0
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions libpkg/pkg_add.c
Original file line number Diff line number Diff line change
Expand Up @@ -502,9 +502,10 @@ create_hardlink(struct pkg *pkg, struct pkg_file *f, const char *path, tempdirs_
{
bool tried_mkdir = false;
struct pkg_file *fh;
int fd;
int fd, fdh;
const char *pathfrom, *pathto;
struct tempdir *tmpdir = NULL;
struct tempdir *tmphdir = NULL;

tll_foreach(*tempdirs, t) {
if (strncmp(t->item->name, f->path, t->item->len) == 0 && f->path[t->item->len] == '/' ) {
Expand All @@ -530,19 +531,36 @@ create_hardlink(struct pkg *pkg, struct pkg_file *f, const char *path, tempdirs_
" hardlinked to %s", f->path, path);
return (EPKG_FATAL);
}
if (fh->temppath[0] == '\0') {
tll_foreach(*tempdirs, t) {
if (strncmp(t->item->name, fh->path, t->item->len) == 0 &&
fh->path[t->item->len] == '/' ) {
tmphdir = t->item;
break;
}
}
}
if (tmpdir == NULL) {
pathfrom = fh->temppath;
pathto = f->temppath;
fd = pkg->rootfd;
} else {
pathfrom = fh->path + tmpdir->len;
pathto = f->path + tmpdir->len;
fd = tmpdir->fd;
}

if (tmphdir == NULL) {
pathfrom = fh->temppath;
fdh = pkg->rootfd;
} else {
pathfrom = fh->path + tmphdir->len;
fdh = tmphdir->fd;
}

retry:
if (linkat(fd, RELATIVE_PATH(pathfrom),
if (linkat(fdh, RELATIVE_PATH(pathfrom),
fd, RELATIVE_PATH(pathto), 0) == -1) {
if (!tried_mkdir) {
if (!try_mkdir(fd, pathfrom))
if (!try_mkdir(fd, pathto))
return (EPKG_FATAL);
tried_mkdir = true;
goto retry;
Expand Down

0 comments on commit 0a8b8a0

Please sign in to comment.