Skip to content

Commit

Permalink
[linker] OutputStep should not create readonly files
Browse files Browse the repository at this point in the history
File.Copy will preserve permissions and create readonly files.
We should create writeable files instead.

See mono/mono#10743
  • Loading branch information
lambdageek authored and marek-safar committed Oct 3, 2018
1 parent 5648356 commit 7af03ce
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions linker/Linker.Steps/OutputStep.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,18 +213,27 @@ protected virtual void CopyAssembly (AssemblyDefinition assembly, string directo
if (source == target)
return;

File.Copy (source, target, true);
CopyFileAndRemoveReadOnly (source, target);

if (!Context.LinkSymbols)
return;

var mdb = source + ".mdb";
if (File.Exists (mdb))
File.Copy (mdb, target + ".mdb", true);
CopyFileAndRemoveReadOnly (mdb, target + ".mdb");

var pdb = Path.ChangeExtension (source, "pdb");
if (File.Exists (pdb))
File.Copy (pdb, Path.ChangeExtension (target, "pdb"), true);
CopyFileAndRemoveReadOnly (pdb, Path.ChangeExtension (target, "pdb"));
}

static void CopyFileAndRemoveReadOnly (string src, string dest) {
File.Copy (src, dest, true);

FileAttributes attrs = File.GetAttributes (dest);

if ((attrs & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
File.SetAttributes (dest, attrs & ~FileAttributes.ReadOnly);
}

protected virtual string GetAssemblyFileName (AssemblyDefinition assembly, string directory)
Expand Down

0 comments on commit 7af03ce

Please sign in to comment.