Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

npx cpy-cli --nooverwrite produces an error when file exists. Expected skip #45

Open
jafin opened this issue Jul 16, 2023 · 2 comments
Open

Comments

@jafin
Copy link

jafin commented Jul 16, 2023

Platform

windows 11 22H2
cpy-cli@5.0.0

When I execute

npx cpy-cli .\test.json foo\ --no-overwrite

it returns the error

Cannot copy from `test.json` to `d:\temp\foo\test.json`: 
Cannot write to `d:\temp\foo\test.json`: EEXIST: file already exists, open 'd:\temp\foo\test.json'

Issuing the command without --no-overwrite works fine (but the file is overwritten)

Expected

when setting the --no-overwrite parameter it should continue without error even if the file exists.

My Misunderstanding of purpose?

I found the test for cpy, it appears it is expected that overwrite:false will throw an exception? If so is there any way to 'skip/ignore' existing files similar to how the non async approach appears to work?

test('do not overwrite', async t => {
	fs.mkdirSync(t.context.tmp);
	fs.writeFileSync(path.join(t.context.tmp, 'license'), '');

	await t.throwsAsync(cpy(['license'], t.context.tmp, {overwrite: false}));

	t.is(read(t.context.tmp, 'license'), '');
});

EDIT: reading cp-file code, if I understand async copy overwrite false will throw an exception, but sync copy overwrite will not. If that is correct, then this was just a misunderstanding, please close the issue.

@sindresorhus
Copy link
Owner

It's working as intended, but we could maybe add another flag to not throw when the file already exists. For example, inspired by rsync:

--ignore-existing skip updating files that already exist on receiver

@staff0rd
Copy link

I am interested in adding such functionality, but i'm uncertain where it should go after seeing the dependency chain: cpy-cli > cpy > copy-file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants