Skip to content

Commit 5d747f6

Browse files
committed
Try to handle too long target path names which already exist
1 parent 0a2b667 commit 5d747f6

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

Program.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -822,7 +822,9 @@ public static async Task SaveFileModifications(string fullName, string fileData,
822822
{
823823
await DeleteFile(otherFullName, context);
824824

825-
Directory.CreateDirectory(Path.GetDirectoryName(otherFullName));
825+
var otherDirName = Path.GetDirectoryName(otherFullName);
826+
if (!Directory.Exists(otherDirName))
827+
Directory.CreateDirectory(otherDirName);
826828

827829
//@"\\?\" prefix is needed for writing to long paths: https://stackoverflow.com/questions/44888844/directorynotfoundexception-when-using-long-paths-in-net-4-7
828830
await FileExtensions.WriteAllTextAsync(@"\\?\" + otherFullName, fileData, context.Token);
@@ -869,7 +871,9 @@ public static async Task SaveFileModifications(string fullName, byte[] fileData,
869871
{
870872
await DeleteFile(otherFullName, context);
871873

872-
Directory.CreateDirectory(Path.GetDirectoryName(otherFullName));
874+
var otherDirName = Path.GetDirectoryName(otherFullName);
875+
if (!Directory.Exists(otherDirName))
876+
Directory.CreateDirectory(otherDirName);
873877

874878
//@"\\?\" prefix is needed for writing to long paths: https://stackoverflow.com/questions/44888844/directorynotfoundexception-when-using-long-paths-in-net-4-7
875879
await FileExtensions.WriteAllBytesAsync(@"\\?\" + otherFullName, fileData, context.Token);

0 commit comments

Comments
 (0)