Bug 17009 - File.Move() wont honor (FileShare.ReadWrite | FileShare.Delete)
Summary: File.Move() wont honor (FileShare.ReadWrite | FileShare.Delete)
Status: RESOLVED FIXED
Alias: None
Product: Runtime
Classification: Mono
Component: io-layer ()
Version: 3.2.x
Hardware: PC All
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2014-01-01 04:23 UTC by Pablo Ruiz García
Modified: 2014-01-08 20:47 UTC (History)
3 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Pablo Ruiz García 2014-01-01 04:23:26 UTC
The following code fails with 'Sharing violation on path ...', however it works fine on ms.net (as it is supposed to due to sharing flags used):

using System.IO;

var file = "/tmp/kk";
var share = FileShare.ReadWrite | FileShare.Delete;

using (var stream = new FileStream(file, FileMode.Open, FileAccess.Read, share, 4096, FileOptions.SequentialScan))
{
	File.Move(file, file + ".old");
}

System.IO.IOException: Sharing violation on path /tmp/kk
  at System.IO.File.Move (System.String sourceFileName, System.String destFileName) [0x00000] in <filename unknown>:0
  at <InteractiveExpressionClass>.Host (System.Object& $retval) [0x00000] in <filename unknown>:0
  at Mono.CSharp.Evaluator.Evaluate (System.String input, System.Object& result, System.Boolean& result_set) [0x00000] in <filename unknown>:0
  at Mono.CSharpShell.Evaluate (System.String input) [0x00000] in <filename unknown>:0
Comment 1 Pablo Ruiz García 2014-01-01 04:29:03 UTC
As a side note, this alternative code works fine, demostrating the OS allos to move/rename the file without any problem:

using System.IO;

var file = "/tmp/kk";
var share = FileShare.ReadWrite | FileShare.Delete;

using (var stream = new FileStream(file, FileMode.Open, FileAccess.Read, share, 4096, FileOptions.SequentialScan))
{
	Mono.Unix.Native.Syscall.system("mv " + file + " " + file + ".old");
}
Comment 2 Rodrigo Kumpera 2014-01-08 20:47:18 UTC
Fixed in master. Thanks for the report.