#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 <errno.h>
#include <fcntl.h>
# include <utime.h>
#endif
+#ifndef O_NOFOLLOW
+# define O_NOFOLLOW 0
+#endif
+
static int
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);
+ int fd = open(path, O_TRUNC | O_CREAT | O_WRONLY | O_NOFOLLOW, 0644);
if (fd < 0)
return WIMLIB_ERR_OPEN;
close(fd);
}
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;
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;
}
int (*makelink)(const tchar *oldpath, const tchar *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;
+ 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_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;
- raw_fd = open(path, O_WRONLY | O_TRUNC);
+ raw_fd = open(path, O_WRONLY | O_TRUNC | O_NOFOLLOW);
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;