Skip to content

Commit

Permalink
Revert "Re-use directory discovery logic"
Browse files Browse the repository at this point in the history
This reverts commit 338ff35.
  • Loading branch information
mimischi committed Dec 10, 2024
1 parent 7ed6d7d commit e9df08e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 18 deletions.
26 changes: 9 additions & 17 deletions Sources/NIOFileSystem/FileSystem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -438,37 +438,29 @@ public struct FileSystem: Sendable, FileSystemProtocol {
}
}

func _collectItemsInDirectory(at path: FilePath) async throws -> ([FilePath], [FilePath]) {
try await self.withDirectoryHandle(
@discardableResult
private func removeItemSequentially(
at path: FilePath
) async throws -> Int {
var (subdirectories, filesRemoved) = try await self.withDirectoryHandle(
atPath: path
) { directory in
var subdirectories = [FilePath]()
var nonDirectoryItems = [FilePath]()
var filesRemoved = 0

for try await batch in directory.listContents().batched() {
for entry in batch {
switch entry.type {
case .directory:
subdirectories.append(entry.path)

default:
nonDirectoryItems.append(entry.path)
filesRemoved += try await self.removeOneItem(at: entry.path)
}
}
}

return (subdirectories, nonDirectoryItems)
}
}

@discardableResult
private func removeItemSequentially(
at path: FilePath
) async throws -> Int {
var filesRemoved = 0
let (subdirectories, itemsToRemove) = try await self._collectItemsInDirectory(at: path)

for item in itemsToRemove {
filesRemoved += try await self.removeOneItem(at: item)
return (subdirectories, filesRemoved)
}

for subdirectory in subdirectories {
Expand Down
18 changes: 17 additions & 1 deletion Sources/NIOFileSystem/Internal/ParallelRemoval.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,23 @@ extension FileSystem {
// Discover current directory and find all files/directories. Free up
// the handle as fast as possible.
let (directoriesToRecurseInto, itemsToDelete) = try await bucket.withToken {
try await self._collectItemsInDirectory(at: path)
try await self.withDirectoryHandle(atPath: path) { directory in
var subdirectories: [FilePath] = []
var itemsInDirectory: [FilePath] = []

for try await batch in directory.listContents().batched() {
for entry in batch {
switch entry.type {
case .directory:
subdirectories.append(entry.path)
default:
itemsInDirectory.append(entry.path)
}
}
}

return (subdirectories, itemsInDirectory)
}
}

return try await withThrowingTaskGroup(of: Int.self) { group in
Expand Down

0 comments on commit e9df08e

Please sign in to comment.