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

fs.move deletes original file and throws error failing to rename/move #614

Closed
kdcro101 opened this issue Aug 6, 2018 · 5 comments
Closed

Comments

@kdcro101
Copy link

kdcro101 commented Aug 6, 2018

  • Operating System: Windows 10
  • Node.js version: 10.2.1
  • fs-extra version: 6.0.0, 7.0.0

when renaming (using fs.move + overwrite:true) file from: C:\DIR\file.txt to C:\DIR\FILE.txt (from lowercase to uppercase and vice versa) original file is deleted and error is thrown that file doesn't exist.

On linux everything works as expected.

@RyanZim
Copy link
Collaborator

RyanZim commented Aug 6, 2018

@manidlou Could you have a look at this?

@manidlou
Copy link
Collaborator

manidlou commented Aug 7, 2018

ooh yeah I know what's happening here! @RyanZim @kdcro101 Windows is a case-insensitive system meaning in Windows world file.txt and FILE.txt are the same and since {overwrite: true} the dest file gets removed while src and dest are actually the same, therefore we end up removing src file!

We applied the fix for handling case-insensitive paths to copy*() but move*() is still buggy and needs to be fixed. I'll be working on it. I do my best to make the fix ready for v8 release.

@bluelovers
Copy link

lloks like this issues still exists

@bluelovers
Copy link

a stupid way

import * as fs from 'fs-extra';

export function win32_move(src: string, dest: string, options?: fs.MoveOptions)
{
	return fs.move(src, dest, options)
		.catch(function (e)
		{
			if (process.platform ==='win32')
			{
				if (/dest already exists/i.test(e.message))
				{
					if (src.toLowerCase() === dest.toLowerCase())
					{
						return;
					}
				}
			}

			return Promise.reject(e)
		})
	;
}

@manidlou manidlou mentioned this issue Apr 1, 2019
@RyanZim
Copy link
Collaborator

RyanZim commented May 11, 2019

Should be fixed in #667

@RyanZim RyanZim closed this as completed May 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants