Skip to content

Commit 084bf9f

Browse files
authored
Merge pull request #815 from unoplatform/dev/jela/readonly-source
fix: Remove readonly attribute for output path deletion
2 parents 8ed40d1 + 72ea52d commit 084bf9f

File tree

5 files changed

+85
-13
lines changed

5 files changed

+85
-13
lines changed

.vsts-ci-windows-tests.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ jobs:
2929
version: 8.0.100
3030
includePreviewVersions: true
3131

32+
- pwsh: |
33+
attrib +r "$(build.sourcesdirectory)/src" /s /d
34+
displayName: Set all repo files as readonly
35+
3236
- pwsh: |
3337
cd $(build.sourcesdirectory)/src/Uno.Wasm.Bootstrap
3438
dotnet msbuild /r /p:Configuration=Release /p:DISABLE_CLIHOST_NET6=true

src/Uno.Wasm.Bootstrap/Extensions/PathHelper.cs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.IO;
1+
using System;
2+
using System.IO;
23

34
namespace Uno.Wasm.Bootstrap.Extensions;
45

@@ -13,4 +14,31 @@ private static readonly char OtherDirectorySeparatorChar
1314
public static string FixupPath(string path)
1415
=> path.Replace(OtherDirectorySeparatorChar, Path.DirectorySeparatorChar);
1516

17+
/// <summary>
18+
/// Recursively deletes a path, including files with the readonly attribute
19+
/// </summary>
20+
public static void DeleteDirectory(string path)
21+
{
22+
if (Directory.Exists(path))
23+
{
24+
if (Environment.OSVersion.Platform == PlatformID.Win32NT)
25+
{
26+
// Some files may have been copied over from the source
27+
// files with a readonly attribute, let's remove it before deleting
28+
29+
foreach (var file in Directory.GetFiles(path, "*", SearchOption.AllDirectories))
30+
{
31+
var attributes = File.GetAttributes(file);
32+
33+
if ((attributes & FileAttributes.ReadOnly) != 0)
34+
{
35+
File.SetAttributes(file, attributes & ~FileAttributes.ReadOnly);
36+
}
37+
}
38+
}
39+
40+
// Delete all files and folders recursively
41+
Directory.Delete(path, true);
42+
}
43+
}
1644
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// ******************************************************************
2+
// Copyright � 2015-2022 Uno Platform inc. All rights reserved.
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
//
16+
// ******************************************************************
17+
//
18+
// This file is based on the work from https://github.com/praeclarum/Ooui
19+
//
20+
using System;
21+
using System.Collections.Generic;
22+
using System.Diagnostics;
23+
using System.IO;
24+
using System.Linq;
25+
using Microsoft.Build.Framework;
26+
using Microsoft.Build.Utilities;
27+
using Uno.Wasm.Bootstrap.Extensions;
28+
29+
namespace Uno.Wasm.Bootstrap;
30+
31+
public class RemoveDirTask_v0 : Microsoft.Build.Utilities.Task
32+
{
33+
[Required]
34+
public string Path { get; private set; } = "";
35+
36+
public override bool Execute()
37+
{
38+
var fixedPath = PathHelper.FixupPath(Path);
39+
PathHelper.DeleteDirectory(fixedPath);
40+
41+
return true;
42+
}
43+
}

src/Uno.Wasm.Bootstrap/ShellTask.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -771,7 +771,7 @@ private void RunPackager()
771771

772772
if (Directory.Exists(workAotPath))
773773
{
774-
Directory.Delete(workAotPath, true);
774+
DirectoryDelete(workAotPath);
775775
}
776776

777777
DirectoryCreateDirectory(workAotPath);
@@ -988,7 +988,7 @@ private void RunPackager()
988988

989989
if (Directory.Exists(linkerInput))
990990
{
991-
Directory.Delete(linkerInput, true);
991+
DirectoryDelete(linkerInput);
992992
}
993993

994994
Directory.Move(_managedPath, linkerInput);
@@ -1579,7 +1579,7 @@ IEnumerable<byte> ComputeHash(string file)
15791579

15801580
if (Directory.Exists(_distPath))
15811581
{
1582-
Directory.Delete(_distPath, true);
1582+
DirectoryDelete(_distPath);
15831583
}
15841584

15851585
try
@@ -1606,6 +1606,9 @@ IEnumerable<byte> ComputeHash(string file)
16061606
TryObfuscateAssemblies(Path.Combine(_finalPackagePath, Path.GetFileName(_managedPath)));
16071607
}
16081608

1609+
private void DirectoryDelete(string path)
1610+
=> PathHelper.DeleteDirectory(path);
1611+
16091612
private static void MoveFileSafe(string source, string target)
16101613
{
16111614
if (File.Exists(source) && source != target)
@@ -1688,12 +1691,12 @@ private void CreateDist()
16881691

16891692
if (Directory.Exists(_workDistPath))
16901693
{
1691-
Directory.Delete(_workDistPath, true);
1694+
DirectoryDelete(_workDistPath);
16921695
}
16931696

16941697
if (Directory.Exists(_workDistRootPath))
16951698
{
1696-
Directory.Delete(_workDistRootPath, true);
1699+
DirectoryDelete(_workDistRootPath);
16971700
}
16981701

16991702
Log.LogMessage($"Creating managed path {_managedPath}");

src/Uno.Wasm.Bootstrap/build/Uno.Wasm.Bootstrap.targets

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -310,13 +310,7 @@
310310
<WasmShellDistPath Condition="'$(WasmShellDistPath)'==''">$(OutputPath)/dist</WasmShellDistPath>
311311
</PropertyGroup>
312312

313-
<ItemGroup>
314-
<_DistFilesToDelete Include="$(OutputPath)dist\**" />
315-
<_DistDirToDelete Include="$([System.IO.Directory]::GetDirectories(&quot;$(WasmShellDistPath)&quot;))" Condition="exists('$(WasmShellDistPath)')" />
316-
</ItemGroup>
317-
318-
<Delete Files="@(_DistFilesToDelete)" />
319-
<RemoveDir Directories="@(_DistDirToDelete)" />
313+
<RemoveDirTask_v0 Path="$(WasmShellDistPath)" />
320314
</Target>
321315

322316
<Target Name="_ValidateLegacyCLIPackage" BeforeTargets="CoreCompile">

0 commit comments

Comments
 (0)