+/*
+ * capture_common.c - Mostly code to handle excluding paths from capture.
+ */
+
/*
* Copyright (C) 2013 Eric Biggers
*
* along with wimlib; if not, see http://www.gnu.org/licenses/.
*/
-#include "wimlib_internal.h"
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
-#include <string.h>
+#include "wimlib/assert.h"
+#include "wimlib/capture.h"
+#include "wimlib/error.h"
+#include "wimlib/paths.h"
#ifdef __WIN32__
-# include "win32.h"
+# include "wimlib/win32.h" /* for fnmatch() equivalent */
#else
# include <fnmatch.h>
#endif
+#include <string.h>
+
static int
canonicalize_pattern(const tchar *pat, tchar **canonical_pat_ret)
{
tchar *canonical_pat;
- if (pat[0] != T('/') && pat[0] != T('\\') &&
+ if (!is_any_path_separator(pat[0]) &&
pat[0] != T('\0') && pat[1] == T(':'))
{
/* Pattern begins with drive letter */
- if (pat[2] != T('/') && pat[2] != T('\\')) {
+ if (!is_any_path_separator(pat[2])) {
/* Something like c:file, which is actually a path
* relative to the current working directory on the c:
* drive. We require paths with drive letters to be
* absolute. */
ERROR("Invalid path \"%"TS"\"; paths including drive letters "
"must be absolute!", pat);
- ERROR("Maybe try \"%"TC":/%"TS"\"?",
+ ERROR("Maybe try \"%"TC":\\%"TS"\"?",
pat[0], pat + 2);
return WIMLIB_ERR_INVALID_CAPTURE_CONFIG;
}
canonical_pat = canonicalize_fs_path(pat);
if (!canonical_pat)
return WIMLIB_ERR_NOMEM;
+
+ /* Translate all possible path separators into the operating system's
+ * preferred path separator. */
+ for (tchar *p = canonical_pat; *p; p++)
+ if (is_any_path_separator(*p))
+ *p = OS_PREFERRED_PATH_SEPARATOR;
*canonical_pat_ret = canonical_pat;
return 0;
}
const tchar *pat = list->pats[i];
const tchar *string;
- if (*pat == T('/')) {
+ if (*pat == OS_PREFERRED_PATH_SEPARATOR) {
/* Absolute path from root of capture */
string = path;
} else {
- if (tstrchr(pat, T('/')))
+ if (tstrchr(pat, OS_PREFERRED_PATH_SEPARATOR))
/* Relative path from root of capture */
string = path + 1;
else
exclude_path(const tchar *path, size_t path_len,
const struct wimlib_capture_config *config, bool exclude_prefix)
{
+ if (!config)
+ return false;
const tchar *basename = path_basename_with_len(path, path_len);
if (exclude_prefix) {
wimlib_assert(path_len >= config->_prefix_num_tchars);
if (!tmemcmp(config->_prefix, path, config->_prefix_num_tchars) &&
- path[config->_prefix_num_tchars] == T('/'))
+ path[config->_prefix_num_tchars] == OS_PREFERRED_PATH_SEPARATOR)
{
path += config->_prefix_num_tchars;
}