]> wimlib.net Git - wimlib/blobdiff - src/unix_apply.c
NTFS-3g apply: Open extracted files by MFT reference
[wimlib] / src / unix_apply.c
index fd5d972d404de454bef7dbb28d5a6b26d06977a0..026042bce7219fe1baecfcf5d726b7d40790d73f 100644 (file)
@@ -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;
 
@@ -81,28 +81,41 @@ unix_create_directory(const tchar *path, struct apply_ctx *ctx)
 }
 
 static int
-unix_create_hardlink(const tchar *oldpath, const tchar *newpath,
-                    struct apply_ctx *ctx)
+unix_makelink(const tchar *oldpath, const tchar *newpath,
+             int (*makelink)(const tchar *oldpath, const tchar *newpath))
 {
-       if (link(oldpath, newpath))
+       if ((*makelink)(oldpath, newpath)) {
+               if (errno == EEXIST) {
+                       if (unlink(newpath))
+                               return WIMLIB_ERR_LINK;
+                       if ((*makelink)(oldpath, newpath))
+                               return WIMLIB_ERR_LINK;
+                       return 0;
+               }
                return WIMLIB_ERR_LINK;
+       }
        return 0;
 }
+static int
+unix_create_hardlink(const tchar *oldpath, const tchar *newpath,
+                    struct apply_ctx *ctx)
+{
+       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;