X-Git-Url: https://wimlib.net/git/?a=blobdiff_plain;f=src%2Funix_apply.c;h=21a804a59424bbfa82b8274b0ed4b9a690596b11;hb=06c208689d042c215bb9882232aabb0d98c01875;hp=e27accff294769c9e95b2114ce0b963d81e3a9f7;hpb=61db93f82eca3fe9f7676355c709c58cc425a6ad;p=wimlib diff --git a/src/unix_apply.c b/src/unix_apply.c index e27accff..21a804a5 100644 --- a/src/unix_apply.c +++ b/src/unix_apply.c @@ -29,9 +29,9 @@ #include "wimlib/apply.h" #include "wimlib/error.h" -#include "wimlib/lookup_table.h" #include "wimlib/resource.h" #include "wimlib/timestamp.h" +#include "wimlib/unix_data.h" #include #include @@ -54,7 +54,7 @@ unix_start_extract(const char *target, struct apply_ctx *ctx) } static int -unix_create_file(const char *path, struct apply_ctx *ctx) +unix_create_file(const char *path, struct apply_ctx *ctx, u64 *cookie_ret) { int fd = open(path, O_TRUNC | O_CREAT | O_WRONLY, 0644); if (fd < 0) @@ -64,7 +64,7 @@ unix_create_file(const char *path, struct apply_ctx *ctx) } static int -unix_create_directory(const tchar *path, struct apply_ctx *ctx) +unix_create_directory(const tchar *path, struct apply_ctx *ctx, u64 *cookie_ret) { struct stat stbuf; @@ -72,37 +72,48 @@ unix_create_directory(const tchar *path, struct apply_ctx *ctx) if (errno != EEXIST) return WIMLIB_ERR_MKDIR; if (lstat(path, &stbuf)) - return WIMLIB_ERR_STAT; + return WIMLIB_ERR_MKDIR; errno = EEXIST; if (!S_ISDIR(stbuf.st_mode)) - return WIMLIB_ERR_NOTDIR; + return WIMLIB_ERR_MKDIR; } return 0; } +static int +unix_makelink(const tchar *oldpath, const tchar *newpath, + int (*makelink)(const tchar *oldpath, const tchar *newpath)) +{ + if ((*makelink)(oldpath, newpath)) { + if (errno != EEXIST) + return WIMLIB_ERR_LINK; + if (unlink(newpath)) + return WIMLIB_ERR_LINK; + if ((*makelink)(oldpath, newpath)) + return WIMLIB_ERR_LINK; + } + return 0; +} static int unix_create_hardlink(const tchar *oldpath, const tchar *newpath, struct apply_ctx *ctx) { - if (link(oldpath, newpath)) - return WIMLIB_ERR_LINK; - return 0; + return unix_makelink(oldpath, newpath, link); } static int unix_create_symlink(const tchar *oldpath, const tchar *newpath, struct apply_ctx *ctx) { - if (symlink(oldpath, newpath)) - return WIMLIB_ERR_LINK; - return 0; + return unix_makelink(oldpath, newpath, symlink); } static int -unix_extract_unnamed_stream(const tchar *path, +unix_extract_unnamed_stream(file_spec_t file, struct wim_lookup_table_entry *lte, struct apply_ctx *ctx) { + const char *path = file.path; struct filedes fd; int raw_fd; int ret; @@ -111,7 +122,7 @@ unix_extract_unnamed_stream(const tchar *path, if (raw_fd < 0) return WIMLIB_ERR_OPEN; filedes_init(&fd, raw_fd); - ret = extract_wim_resource_to_fd(lte, &fd, wim_resource_size(lte)); + ret = extract_full_stream_to_fd(lte, &fd); if (filedes_close(&fd) && !ret) ret = WIMLIB_ERR_WRITE; return ret; @@ -124,7 +135,7 @@ unix_set_unix_data(const tchar *path, const struct wimlib_unix_data *data, struct stat stbuf; if (lstat(path, &stbuf)) - return WIMLIB_ERR_STAT; + return WIMLIB_ERR_SET_SECURITY; if (!S_ISLNK(stbuf.st_mode)) if (chmod(path, data->mode)) return WIMLIB_ERR_SET_SECURITY;