Skip to content

Commit

Permalink
Fix bugs when copying directories
Browse files Browse the repository at this point in the history
- CopyDirectoryRecursively would try to create directories on the source FS instead of the destination FS.
- Don't output file name twice in CopyDirectoryRecursively .
  • Loading branch information
Thealexbarney committed Dec 14, 2021
1 parent a76b0ef commit 6910049
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/LibHac/FsSystem/FileSystemExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ static Result OnEnterDir(in Path path, in DirectoryEntry entry,
Result rc = closure.DestinationPathBuffer.AppendChild(entry.Name);
if (rc.IsFailure()) return rc;

return closure.SourceFileSystem.CreateDirectory(in closure.DestinationPathBuffer);
rc = closure.DestFileSystem.CreateDirectory(in closure.DestinationPathBuffer);
if (rc.IsFailure() && !ResultFs.PathAlreadyExists.Includes(rc)) return rc.Miss();

return Result.Success;
}

static Result OnExitDir(in Path path, in DirectoryEntry entry, ref Utility.FsIterationTaskClosure closure)
Expand Down Expand Up @@ -92,8 +95,6 @@ public static Result CopyFile(IFileSystem destFileSystem, IFileSystem sourceFile
in Path sourcePath, Span<byte> workBuffer, IProgressReport logger = null,
CreateFileOptions option = CreateFileOptions.None)
{
logger?.LogMessage(sourcePath.ToString());

// Open source file.
using var sourceFile = new UniqueRef<IFile>();
Result rc = sourceFileSystem.OpenFile(ref sourceFile.Ref(), sourcePath, OpenMode.Read);
Expand Down Expand Up @@ -136,7 +137,7 @@ public static void Extract(this IFileSystem source, string destinationPath, IPro
{
var destFs = new LocalFileSystem(destinationPath);

source.CopyDirectory(destFs, "/", "/", logger);
source.CopyDirectory(destFs, "/", "/", logger).ThrowIfFailure();
}

public static IEnumerable<DirectoryEntryEx> EnumerateEntries(this IFileSystem fileSystem)
Expand Down

0 comments on commit 6910049

Please sign in to comment.