- /* Translate all possible path separators into the operating system's
- * preferred path separator. */
- for (tchar *p = pat; *p; p++)
- if (is_any_path_separator(*p))
- *p = OS_PREFERRED_PATH_SEPARATOR;
+ /* Collapse consecutive path separators, and translate both / and \ into
+ * / (UNIX) or \ (Windows).
+ *
+ * Note: we expect that this function produces patterns that can be used
+ * for both filesystem paths and WIM paths, so the desired path
+ * separators must be the same. */
+ BUILD_BUG_ON(OS_PREFERRED_PATH_SEPARATOR != WIM_PATH_SEPARATOR);
+ do_canonicalize_path(pat, pat);
+
+ /* Relative patterns can only match file names, so they must be
+ * single-component only. */
+ if (pat[0] != OS_PREFERRED_PATH_SEPARATOR &&
+ tstrchr(pat, OS_PREFERRED_PATH_SEPARATOR))
+ {
+ ERROR("%"TS":%lu: Invalid pattern \"%"TS"\":\n"
+ " Relative patterns can only include one path component!\n"
+ " Maybe try \"%"TC"%"TS"\"?",
+ path, line_no, pat, OS_PREFERRED_PATH_SEPARATOR, pat);
+ return WIMLIB_ERR_INVALID_CAPTURE_CONFIG;
+ }
+