Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed the problem that treeId is sometimes not set correctly in FileR… #169

Merged
merged 1 commit into from
Nov 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 27 additions & 28 deletions Sources/SMBClient/TreeAccessor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,97 +21,96 @@ public class TreeAccessor {
return files.map { File(fileInfo: $0) }
}

public func createDirectory(share: String? = nil, path: String) async throws {
public func createDirectory(path: String) async throws {
try await session().createDirectory(path: Pathname.normalize(path.precomposedStringWithCanonicalMapping))
}

public func rename(share: String? = nil, from: String, to: String) async throws {
try await move(share: share, from: Pathname.normalize(from), to: Pathname.normalize(to))
public func rename(from: String, to: String) async throws {
try await move(from: Pathname.normalize(from), to: Pathname.normalize(to))
}

public func move(share: String? = nil, from: String, to: String) async throws {
public func move(from: String, to: String) async throws {
try await session().move(from: Pathname.normalize(from), to: Pathname.normalize(to.precomposedStringWithCanonicalMapping))
}

public func deleteDirectory(share: String? = nil, path: String) async throws {
public func deleteDirectory(path: String) async throws {
try await session().deleteDirectory(path: Pathname.normalize(path))
}

public func deleteFile(share: String? = nil, path: String) async throws {
public func deleteFile(path: String) async throws {
try await session().deleteFile(path: Pathname.normalize(path))
}

public func fileStat(share: String? = nil, path: String) async throws -> FileStat {
public func fileStat(path: String) async throws -> FileStat {
let response = try await session().fileStat(path: Pathname.normalize(path))
return FileStat(response)
}

public func existFile(share: String? = nil, path: String) async throws -> Bool {
public func existFile(path: String) async throws -> Bool {
try await session().existFile(path: Pathname.normalize(path))
}

public func existDirectory(share: String? = nil, path: String) async throws -> Bool {
public func existDirectory(path: String) async throws -> Bool {
try await session().existDirectory(path: Pathname.normalize(path))
}

public func fileInfo(share: String? = nil, path: String) async throws -> FileAllInformation {
public func fileInfo(path: String) async throws -> FileAllInformation {
let response = try await session().queryInfo(path: Pathname.normalize(path))
return FileAllInformation(data: response.buffer)
}

public func download(share: String? = nil, path: String) async throws -> Data {
let fileReader = fileReader(path: Pathname.normalize(path))
public func download(path: String) async throws -> Data {
let fileReader = try await fileReader(path: Pathname.normalize(path))

let data = try await fileReader.download()
try await fileReader.close()

return data
}

public func upload(share: String? = nil, content: Data, path: String) async throws {
try await upload(share: share, content: content, path: Pathname.normalize(path), progressHandler: { _ in })
public func upload(content: Data, path: String) async throws {
try await upload(content: content, path: Pathname.normalize(path), progressHandler: { _ in })
}

public func upload(share: String? = nil, content: Data, path: String, progressHandler: (_ progress: Double) -> Void) async throws {
let fileWriter = fileWriter(share: share, path: Pathname.normalize(path))
public func upload(content: Data, path: String, progressHandler: (_ progress: Double) -> Void) async throws {
let fileWriter = try await fileWriter(path: Pathname.normalize(path))

try await fileWriter.upload(data: content, progressHandler: progressHandler)
try await fileWriter.close()
}

public func upload(share: String? = nil, fileHandle: FileHandle, path: String) async throws {
try await upload(share: share, fileHandle: fileHandle, path: path, progressHandler: { _ in })
public func upload(fileHandle: FileHandle, path: String) async throws {
try await upload(fileHandle: fileHandle, path: path, progressHandler: { _ in })
}

public func upload(share: String? = nil, fileHandle: FileHandle, path: String, progressHandler: (_ progress: Double) -> Void) async throws {
let fileWriter = fileWriter(share: share, path: Pathname.normalize(path))
public func upload(fileHandle: FileHandle, path: String, progressHandler: (_ progress: Double) -> Void) async throws {
let fileWriter = try await fileWriter(path: Pathname.normalize(path))

try await fileWriter.upload(fileHandle: fileHandle, progressHandler: progressHandler)
try await fileWriter.close()
}

public func upload(share: String? = nil, localPath: URL, remotePath path: String) async throws {
try await upload(share: share, localPath: localPath, remotePath: path, progressHandler: { _, _, _ in })
public func upload(localPath: URL, remotePath path: String) async throws {
try await upload(localPath: localPath, remotePath: path, progressHandler: { _, _, _ in })
}

public func upload(
share: String? = nil,
localPath: URL,
remotePath path: String,
progressHandler: (_ completedFiles: Int, _ fileBeingTransferred: URL, _ bytesSent: Int64) -> Void
) async throws {
let fileWriter = fileWriter(share: share, path: Pathname.normalize(path))
let fileWriter = try await fileWriter(path: Pathname.normalize(path))

try await fileWriter.upload(localPath: localPath, progressHandler: progressHandler)
try await fileWriter.close()
}

public func fileReader(share: String? = nil, path: String) -> FileReader {
FileReader(session: session, path: Pathname.normalize(path))
public func fileReader(path: String) async throws -> FileReader {
FileReader(session: try await session(), path: Pathname.normalize(path))
}

public func fileWriter(share: String? = nil, path: String) -> FileWriter {
FileWriter(session: session, path: Pathname.normalize(path))
public func fileWriter(path: String) async throws -> FileWriter {
FileWriter(session: try await session(), path: Pathname.normalize(path))
}

public func availableSpace() async throws -> UInt64 {
Expand Down
Loading