When running external ZIP program, ensures that
the files are stored with a path relative to the
root directory by changing the directory first.
Also, tiny improvement in working directory handling.
Change-Id: I3470c6c933aea9cd93dac197ff7f5e8a0ed86b23
Signed-off-by: Jose Bollo <jose.bollo@iot.bzh>
/* compute absolutes paths */
x = realpath(wgtfile, NULL);
if (x == NULL) {
- ERROR("realpath failed for %s",wgtfile);
+ ERROR("realpath failed for %s", wgtfile);
return 1;
}
wgtfile = x;
/* set and enter the workdir */
- if (set_workdir(directory, 0))
+ if (chdir(directory)) {
+ ERROR("failed to enter directory %s", directory);
+ return 1;
+ }
+ if (set_workdir(".", 0))
return 1;
workdir[1] = 0;
workdirfd = AT_FDCWD;
} else {
-
+
assert(length < sizeof workdir);
memcpy(workdir, name, 1 + length);
workdirfd = fd;
return -1;
}
+ /* check if . */
+ if (length == 1 && name[0] == '.') {
+ put_workdir(AT_FDCWD, name, length);
+ return 0;
+ }
+
/* opens the directory */
dirfd = openat(AT_FDCWD, name, O_PATH|O_DIRECTORY|O_RDONLY);
if (dirfd < 0) {