Skip to content

Renaming is failing when destination is the same folder as origin #49

Description

@moelders

Hello,

I would like to share an issue that I found while I was trying to copy and rename a file which destination is the same as its current folder. It worked fine in v2.0.1.

CpyError: Refusing to copy to itself

I have tried to modify the code but it is very complex to understand where exactly renaming function must be executed. However, I have written a test to show you the error:

// test.js
test('rename at the same directory', async t => {
	fs.mkdirSync(t.context.tmp);
	fs.mkdirSync(path.join(t.context.tmp, 'dest'));
	fs.writeFileSync(path.join(t.context.tmp, 'hello.js'), 'console.log("hello");');

	await execa('./cli.js', [path.join(t.context.tmp, 'hello.js'), path.join(t.context.tmp, './'), '--rename=file-renamed.js']);

	t.is(read(t.context.tmp, 'file-renamed.js'), 'console.log("hello");');
});
 ✘ [fail]: rename to the same directory Rejected promise returned by test

CpyError: Refusing to copy to itself: `/private/var/folders/7g/nqj3y3v55jdddlg604cf973h0000gp/T/b60e1889-1101-48ae-9d08-9075e8881508/hello.js`

As I said, I would have like to open a PR but I could not find a proper solution. I hope you can find it.

Thank you!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions