Skip to content

Commit

Permalink
Truncate file prior writting to it
Browse files Browse the repository at this point in the history
  • Loading branch information
vsarunas committed Jul 24, 2024
1 parent 237e7bf commit bb27ebd
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion Sources/SotoS3FileTransfer/S3FileTransferManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,9 @@ public final class S3FileTransferManager: Sendable {
}
return to
}
try await self.fileIO.withFileHandle(path: filename, mode: .write, flags: .allowFileCreation()) { fileHandle in
// if the file exists truncate prior writting to it
let fileHandleFlags = NIOFileHandle.Flags.posix(flags: O_CREAT | O_TRUNC, mode: NIOFileHandle.Flags.defaultPermissions)
try await self.fileIO.withFileHandle(path: filename, mode: .write, flags: fileHandleFlags) { fileHandle in
let request = S3.GetObjectRequest(bucket: from.bucket, key: from.key, options: options)
let response = try await self.s3.getObject(request, logger: self.logger)
var bytesDownloaded = 0
Expand Down

0 comments on commit bb27ebd

Please sign in to comment.