Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fs: add test for cpSync
  • Loading branch information
thoqbk committed Oct 2, 2022
commit ec30bf05e4678ae2e3d2e9768e6ed340e857d7ae
18 changes: 18 additions & 0 deletions test/parallel/test-fs-cp.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,24 @@ if (!isWindows) {
}, { code: 'ERR_INVALID_RETURN_VALUE' });
}

// It should not throw exception if child folder
// does not pass filter function
Comment thread
thoqbk marked this conversation as resolved.
Outdated
{
// Create a file in dest with the same name as a child folder in src
// expect: this shouldn't throw error since filtered out by filter function
const src = nextdir();
mkdirSync(join(src, 'foo'), mustNotMutateObjectDeep({ recursive: true }));

const dest = nextdir();
mkdirSync(dest, mustNotMutateObjectDeep({ recursive: true }));
writeFileSync(join(dest, 'foo'), 'foo-content', mustNotMutateObjectDeep({ mode: 0o444 }));

cpSync(src, dest, {
filter: (path) => !path.includes('foo'),
recursive: true,
});
}
Copy link
Copy Markdown
Contributor Author

@thoqbk thoqbk Oct 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before fixing, when I run this test it throws the following error because checkPathsSync(srcItem, destItem, opts) gets called even though the srcItem shouldn't be copied:

    SystemError [ERR_FS_CP_DIR_TO_NON_DIR]: Cannot overwrite directory with non-directory: cp returned EISDIR (cannot overwrite directory /Users/xxx/dev/node/test/.tmp.0/copy_28/foo with non-directory /Users/xxx/dev/node/test/.tmp.0/copy_29/foo) /Users/xxx/dev/node/test/.tmp.0/copy_29/foo
        at new SystemError (node:internal/errors:244:5)
        at new NodeError (node:internal/errors:355:7)
        at checkPathsSync (node:internal/fs/cp/cp-sync:77:13)
        at copyDir (node:internal/fs/cp/cp-sync:287:28)
        at onDir (node:internal/fs/cp/cp-sync:268:10)
        at getStats (node:internal/fs/cp/cp-sync:171:12)
        at handleFilterAndCopy (node:internal/fs/cp/cp-sync:158:10)
        at cpSyncFn (node:internal/fs/cp/cp-sync:60:10)
        at cpSync (node:fs:2899:3)
        at file:///Users/xxx/dev/node/test/parallel/test-fs-cp.mjs:353:3 {
      code: 'ERR_FS_CP_DIR_TO_NON_DIR',
      info: {
        message: 'cannot overwrite directory /Users/xxx/dev/node/test/.tmp.0/copy_28/foo with non-directory /Users/xxx/dev/node/test/.tmp.0/copy_29/foo',
        path: '/Users/xxx/dev/node/test/.tmp.0/copy_29/foo',
        syscall: 'cp',
        errno: 21,
        code: 'EISDIR'
      },
      errno: [Getter/Setter],
      syscall: [Getter/Setter],
      path: [Getter/Setter]
    }


// It throws error if errorOnExist is true, force is false, and file or folder
// copied over.
{
Expand Down