-#include "config.h"
+/*
+ * unix_apply.c - Code to apply files from a WIM image on UNIX.
+ */
+
+/*
+ * Copyright (C) 2012, 2013 Eric Biggers
+ *
+ * This file is part of wimlib, a library for working with WIM files.
+ *
+ * wimlib is free software; you can redistribute it and/or modify it under the
+ * terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 3 of the License, or (at your option)
+ * any later version.
+ *
+ * wimlib is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ * A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with wimlib; if not, see http://www.gnu.org/licenses/.
+ */
-#ifdef HAVE_UTIME_H
-# include <utime.h>
+#ifndef __WIN32__
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
#endif
+
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <unistd.h>
+#ifdef HAVE_UTIME_H
+# include <utime.h>
+#endif
-#include "timestamp.h"
-#include "wimlib_internal.h"
-#include "lookup_table.h"
+#include "wimlib/apply.h"
+#include "wimlib/error.h"
+#include "wimlib/lookup_table.h"
+#include "wimlib/reparse.h"
+#include "wimlib/timestamp.h"
/* Returns the number of components of @path. */
static unsigned
}
static int
-extract_regular_file_linked(struct wim_dentry *dentry,
- const char *output_path,
- struct apply_args *args,
- struct wim_lookup_table_entry *lte)
+unix_extract_regular_file_linked(struct wim_dentry *dentry,
+ const char *output_path,
+ struct apply_args *args,
+ struct wim_lookup_table_entry *lte)
{
/* This mode overrides the normal hard-link extraction and
* instead either symlinks or hardlinks *all* identical files in
char *p;
const char *p2;
size_t i;
+ const struct wim_dentry *d;
- num_path_components = get_num_path_components(dentry->_full_path) - 1;
+ num_path_components = 0;
+ for (d = dentry; d != args->extract_root; d = d->parent)
+ num_path_components++;
+ wimlib_assert(num_path_components > 0);
+ num_path_components--;
num_output_dir_path_components = get_num_path_components(args->target);
if (args->extract_flags & WIMLIB_EXTRACT_FLAG_MULTI_IMAGE) {
}
static int
-extract_regular_file_unlinked(struct wim_dentry *dentry,
- struct apply_args *args,
- const char *output_path,
- struct wim_lookup_table_entry *lte)
+unix_extract_regular_file_unlinked(struct wim_dentry *dentry,
+ struct apply_args *args,
+ const char *output_path,
+ struct wim_lookup_table_entry *lte)
{
/* Normal mode of extraction. Regular files and hard links are
* extracted in the way that they appear in the WIM. */
}
static int
-extract_regular_file(struct wim_dentry *dentry,
- struct apply_args *args,
- const char *output_path)
+unix_extract_regular_file(struct wim_dentry *dentry,
+ struct apply_args *args,
+ const char *output_path)
{
struct wim_lookup_table_entry *lte;
const struct wim_inode *inode = dentry->d_inode;
WIMLIB_EXTRACT_FLAG_HARDLINK)))
{
if (lte->extracted_file) {
- return extract_regular_file_linked(dentry, output_path, args, lte);
+ return unix_extract_regular_file_linked(dentry,
+ output_path,
+ args, lte);
} else {
lte->extracted_file = STRDUP(output_path);
if (!lte->extracted_file)
return WIMLIB_ERR_NOMEM;
}
}
- return extract_regular_file_unlinked(dentry, args, output_path, lte);
+ return unix_extract_regular_file_unlinked(dentry, args, output_path, lte);
}
static int
-extract_symlink(struct wim_dentry *dentry,
- struct apply_args *args,
- const char *output_path)
+unix_extract_symlink(struct wim_dentry *dentry,
+ struct apply_args *args,
+ const char *output_path)
{
char target[4096 + args->target_realpath_len];
char *fixed_target;
if (ret <= 0) {
ERROR("Could not read the symbolic link from dentry `%s'",
- dentry->_full_path);
+ dentry_full_path(dentry));
return WIMLIB_ERR_INVALID_DENTRY;
}
target[args->target_realpath_len + ret] = '\0';
}
static int
-extract_directory(struct wim_dentry *dentry, const tchar *output_path,
- int extract_flags)
+unix_extract_directory(struct wim_dentry *dentry, const char *output_path,
+ int extract_flags)
{
int ret;
struct stat stbuf;
- ret = tstat(output_path, &stbuf);
+ ret = stat(output_path, &stbuf);
if (ret == 0) {
if (S_ISDIR(stbuf.st_mode)) {
- /*if (!is_root)*/
- /*WARNING("`%s' already exists", output_path);*/
goto dir_exists;
} else {
- ERROR("`%"TS"' is not a directory", output_path);
+ ERROR("\"%s\" is not a directory", output_path);
return WIMLIB_ERR_MKDIR;
}
} else {
if (errno != ENOENT) {
- ERROR_WITH_ERRNO("Failed to stat `%"TS"'", output_path);
+ ERROR_WITH_ERRNO("Failed to stat \"%s\"", output_path);
return WIMLIB_ERR_STAT;
}
}
- if (tmkdir(output_path, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH))
- {
- ERROR_WITH_ERRNO("Cannot create directory `%"TS"'", output_path);
+ if (mkdir(output_path, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) {
+ ERROR_WITH_ERRNO("Cannot create directory \"%s\"", output_path);
return WIMLIB_ERR_MKDIR;
}
dir_exists:
ret = 0;
-#ifndef __WIN32__
if (extract_flags & WIMLIB_EXTRACT_FLAG_UNIX_DATA) {
struct wimlib_unix_data unix_data;
ret = inode_get_unix_data(dentry->d_inode, &unix_data, NULL);
ret = dir_apply_unix_data(output_path, &unix_data,
extract_flags);
}
-#endif
return ret;
}
const struct wim_inode *inode = dentry->d_inode;
if (inode_is_symlink(inode))
- return extract_symlink(dentry, args, output_path);
+ return unix_extract_symlink(dentry, args, output_path);
else if (inode_is_directory(inode))
- return extract_directory(dentry, output_path, args->extract_flags);
+ return unix_extract_directory(dentry, output_path, args->extract_flags);
else
- return extract_regular_file(dentry, args, output_path);
+ return unix_extract_regular_file(dentry, args, output_path);
}
int
}
return 0;
}
+
+#endif /* !__WIN32__ */