Skip to content

[Issue]: comparing drive letters is not enough to fix #1206 #1311

@Agritite

Description

@Agritite

What happened?

the fix for #1206 is not robust enough because having the same drive letter is not sufficient to establish that two paths are on the same harddrive.

The reason is that NTFS allows mounting partitions to any empty NTFS folder, basically just like linux mount. One way to do that is through Disk Management (diskmgmt.msc) (https://www.windowscentral.com/how-mount-hard-drive-folder-windows-10). For example here I mounted my D: to ~/Desktop/D:

Image

(Remarks: A direct implication here is that there's no guarantee all partitions have drive letters. Here I can just remove the D drive letter designation, then I would only be able to access this partition through the mounted folder, and that's perfectly legal in Windows.)

Now try

fs.renameSync('~/Desktop/whatever '~/Desktop/D/whatever');

and you'll still get EXDEV, even when the source and destination have the same drive letter.

Another way to trigger this is when you use Docker Windows containers and mount docker volumes. Run a container from windows nanoserver image and mount a volume through docker run -v volume:C:\mounted. Now C:\mounted has drive letter C but trying to rename into it will still trigger EXDEV.

What did you expect to happen?

The correct way to do

func Rename(old, new string) error {
would be something like this:

	err := os.Rename(old, new)
	if err == nil {
		return nil
	}

	DebugLogf("rename failed: %w, fallback to copy", err)

	// If old is a directory, copy recursively
	...

Version

1.2.2

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