Issue saving to Windows “mapped network drive” in Electron

可紊 提交于 2020-03-02 19:32:07

问题


I have an Electron app in early beta and we just got a report that it is not saving correctly to a "DOCUMENTS directory that is using folder redirection to a network location". The user is in a large, IT-managed computing environment.

I work on macOS and only use Windows under emulation to test and debug simple issues, nothing involving networking and I don't know how to handle this.

This is a "presentation tool" type app where the user can "import" (copy) media assets to a project folder, sequence them and save that sequence for later presentation. The typical steps would be, after user launches app and opts to create a new project:

  1. user is presented with a showSaveDialog to select where the project should be saved. The default path specified in the dialog options is app.getPath('documents'). The path returned by that dialog is used for all subsequent copying and saving operations
  2. the project folder is created along with several subfolders for asset types
  3. a JSON file is created at the top level of the project folder and as the user selects media assets on their hard drive (using showOpenDialog), those assets are copied over to the project

Comments from the user:

Creating a project does not save when saving to the windows DOCUMENTS directory that is using folder redirection to a network location. If you save as, then the .json file is created. Asset directorys are not created when starting a new project in the DOCUMENTS directory (that is using folder redirection to a network location).

Saving directly to a mapped drive does work as expected.


I was cleaning out my system drive and found the location where the app was storing the files. Instead of saving in the specified network location it was generating the same folder structure in the root of the C: drive.   So instead of the files being saved to \Server\Username they were being saved to C:\Server\username


Is this some issue with Electron's app.getPath('documents') function? The only manipulation I do to this user-specified project path is to convert it to a UNIX style path using upath in order to make the paths crossplatform compatible.

let projectPath = upath.toUnix(directoryPath);

upath.toUnix(path)

Just converts all `` to / and consolidates duplicates, without performing any normalization.

Could this be stripping out a critical part of the path of a networked drive? Perhaps I should also/instead be using:

upath.normalizeSafe(path)

Exactly like path.normalize(path), but it keeps the first meaningful ./.

Note that the unix / is returned everywhere, so windows \ is always converted to unix /.


Sorry this question is so long but it seems such an odd issue and I don't have an easy means to debug it. If you have read this far, do you see any obvious cause for the issue? I saw this question (FileUtils.copyFile() not creating file when destination is a network path (on windows) maybe it is related? I am just baffled by all the Windows slashes and escaped slashes. . .

来源:https://stackoverflow.com/questions/60355123/issue-saving-to-windows-mapped-network-drive-in-electron

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!