Skip to content
This repository has been archived by the owner on Dec 6, 2024. It is now read-only.

File.Move on a file opened with FileShare.Delete succeeds but throws IOException. #479

Closed
oguimbal opened this issue Jul 13, 2018 · 1 comment
Assignees
Labels
Milestone

Comments

@oguimbal
Copy link

A small snippet being better than a long description:

var dir = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
Directory.CreateDirectory(dir);

 // works
using (var x = File.Open(Path.Combine(dir, "sysio.txt"), FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite | FileShare.Delete))
	System.IO.File.Move(Path.Combine(dir, "sysio.txt"), Path.Combine(dir, "sysio-moved.txt"));
	
// throws, but the move is successfuly performed (The process cannot access the file because it is being used by another process)
using (var x = File.Open(Path.Combine(dir, "alphafs.txt"), FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite | FileShare.Delete))
	Alphaleonis.Win32.Filesystem.File.Move(Path.Combine(dir, "alphafs.txt"),Path.Combine(dir, "alphafs-moved.txt"));

File.Move is supposed to be successful when the file has been open with FileShare.Delete flag.
In this case, File.Move sucessfully moves the file, but throws an exception (wtf ?).

NB: This issue is specific to File.Move, FileShare.Delete works perfectly fine with File.Delete()

@Yomodo Yomodo self-assigned this Jul 13, 2018
@Yomodo Yomodo changed the title [bug] File.Move on a file opened with FileShare.Delete : succeeds, but throws IOException File.Move on a file opened with FileShare.Delete succeeds but throws IOException. Jul 13, 2018
Yomodo added a commit that referenced this issue Jul 13, 2018
Yomodo added a commit that referenced this issue Jul 13, 2018
@Yomodo
Copy link
Collaborator

Yomodo commented Jul 13, 2018

Thanks!

@Yomodo Yomodo closed this as completed Jul 13, 2018
Yomodo added a commit that referenced this issue Jul 13, 2018
@Yomodo Yomodo added this to the vNext milestone Jul 13, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants