- w->fp = fopen(in_wim_path, "rb");
-
- if (!w->fp) {
- ERROR("Failed to open the file \"%s\" for reading: %m\n",
- in_wim_path);
- ret = WIMLIB_ERR_OPEN;
- goto done;
+ /* The absolute path to the WIM is requested so that wimlib_overwrite()
+ * still works even if the process changes its working directory. This
+ * actually happens if a WIM is mounted read-write, since the FUSE
+ * thread changes directory to "/", and it needs to be able to find the
+ * WIM file again.
+ *
+ * This will break if the full path to the WIM changes in the
+ * intervening time...
+ *
+ * Warning: in Windows native builds, realpath() calls the replacement
+ * function in win32.c.
+ */
+ w->filename = realpath(in_wim_path, NULL);
+ if (!w->filename) {
+ ERROR_WITH_ERRNO("Failed to resolve WIM filename");
+ if (errno == ENOMEM)
+ return WIMLIB_ERR_NOMEM;
+ else
+ return WIMLIB_ERR_OPEN;