0

I have an electron app on Mac with full disk permissions. I am using fs to make a directory in a protected folder, and copy files from a temp folder to the new directory.

When using fs.copy, I periodically get two different types of errors:

  • If the directory already exists and is owned by the user:

    • EPERM errors (operation not permitted, unlink xxx) when attempting to overwrite the existing directory, specifically when replacing a manifest.json file. This is very intermittent.
  • If the directory does not exist or is owned by root:

    • EACCES errors when attempting to make the directory or copy files to the new location.

Code:

[...Array(sourceDirs.length).keys()].map(async (idx) => {
    try {
        await fs.ensureDir(destPaths[idx]);    
    }
    catch (e) {
        console.log('Directory does not exist and could not be created');
    }
    try {
        await fs.copy(sourceDirs[idx], destPaths[idx]);
    }
    catch (e) {
        console.log('Copy error:', e);
    }
});
leuenn
  • 11
  • 3

1 Answers1

0

After some more research, I determined that the directory's R/W permissions varied based on what entity created the directory. Some elements of the directory and its children were owned by root, and everyone only had read permissions, while other folders were owned by everyone and had write permissions.

Programmatically, the only way to solve this was by spawning a chmod command with sudo to update the permissions. In my case, there isn't any issue with taking ownership of the directory.

leuenn
  • 11
  • 3