mirror of
https://github.com/leonboe1/QuickDrop.git
synced 2026-11-22 22:36:01 +00:00
Fix: Only one file would be saved for multiple incoming files with same name
This commit is contained in:
1 parent
4bf8a9052d
commit
5429126c1e
1 file changed
+16
-8
@@ -468,9 +468,11 @@ class InboundNearbyConnection: NearbyConnection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private func makeFileDestinationURL(_ initialDest: URL) -> URL {
|
private func makeFileDestinationURL(_ initialDest: URL, usedDestinations: Set<URL>) -> URL {
|
||||||
var dest = initialDest
|
var dest = initialDest
|
||||||
if FileManager.default.fileExists(atPath: dest.path) {
|
let fm = FileManager.default
|
||||||
|
|
||||||
|
if fm.fileExists(atPath: dest.path) || usedDestinations.contains(dest) {
|
||||||
var counter = 1
|
var counter = 1
|
||||||
var path: String
|
var path: String
|
||||||
let ext = dest.pathExtension
|
let ext = dest.pathExtension
|
||||||
@@ -481,8 +483,8 @@ class InboundNearbyConnection: NearbyConnection {
|
|||||||
path += ".\(ext)"
|
path += ".\(ext)"
|
||||||
}
|
}
|
||||||
counter += 1
|
counter += 1
|
||||||
} while FileManager.default.fileExists(atPath: path)
|
dest = URL(fileURLWithPath: path)
|
||||||
dest = URL(fileURLWithPath: path)
|
} while fm.fileExists(atPath: dest.path) || usedDestinations.contains(dest)
|
||||||
}
|
}
|
||||||
return dest
|
return dest
|
||||||
}
|
}
|
||||||
@@ -494,12 +496,18 @@ class InboundNearbyConnection: NearbyConnection {
|
|||||||
|
|
||||||
if frame.v1.introduction.fileMetadata.count > 0 && frame.v1.introduction.textMetadata.isEmpty {
|
if frame.v1.introduction.fileMetadata.count > 0 && frame.v1.introduction.textMetadata.isEmpty {
|
||||||
let saveDirectory = SaveFilesManager.shared.getSaveDirectory()
|
let saveDirectory = SaveFilesManager.shared.getSaveDirectory()
|
||||||
|
var usedDestinations = Set<URL>()
|
||||||
|
|
||||||
for file in frame.v1.introduction.fileMetadata {
|
for file in frame.v1.introduction.fileMetadata {
|
||||||
let dest = makeFileDestinationURL(saveDirectory.appendingPathComponent(file.name))
|
let initialDest = saveDirectory.appendingPathComponent(file.name)
|
||||||
let info = InternalFileInfo(meta: FileMetadata(name: file.name, size: file.size, mimeType: file.mimeType),
|
let dest = makeFileDestinationURL(initialDest, usedDestinations: usedDestinations)
|
||||||
payloadID: file.payloadID,
|
usedDestinations.insert(dest)
|
||||||
destinationURL: dest)
|
|
||||||
|
let info = InternalFileInfo(
|
||||||
|
meta: FileMetadata(name: file.name, size: file.size, mimeType: file.mimeType),
|
||||||
|
payloadID: file.payloadID,
|
||||||
|
destinationURL: dest
|
||||||
|
)
|
||||||
filesToBeReceived[file.payloadID] = info
|
filesToBeReceived[file.payloadID] = info
|
||||||
bytesToBeTransferred += file.size
|
bytesToBeTransferred += file.size
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user