Skip to content

Commit

Permalink
fix: Ensure fake roots have correct uid
Browse files Browse the repository at this point in the history
Signed-off-by: Philippe Weidmann <[email protected]>
  • Loading branch information
PhilippeWeidmann committed Jan 23, 2024
1 parent f86ebb7 commit 76339b3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 5 additions & 1 deletion kDriveCore/Data/Cache/DriveFileManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ public final class DriveFileManager {
}
return freeze ? root.freeze() : root
} else {
return File(id: DriveFileManager.constants.rootID, name: drive.name)
return File(id: DriveFileManager.constants.rootID, name: drive.name, driveId: drive.id)
}
}

Expand Down Expand Up @@ -1565,6 +1565,10 @@ public final class DriveFileManager {
if let cachedFile = getCachedFile(id: file.id, freeze: false, using: realm) {
return cachedFile
} else {
if file.isRoot {
file.driveId = drive.id
file.uid = File.uid(driveId: file.driveId, fileId: file.id)
}
keepCacheAttributesForFile(newFile: file, keepProperties: [.all], using: realm)
try? realm.write {
realm.add(file, update: .all)
Expand Down
6 changes: 5 additions & 1 deletion kDriveCore/Data/Models/File.swift
Original file line number Diff line number Diff line change
Expand Up @@ -794,10 +794,14 @@ public final class File: Object, Codable {
// primary key is set as default value
}

convenience init(id: Int, name: String) {
convenience init(id: Int, name: String, driveId: Int? = nil) {
self.init()
self.id = id
self.name = name
if let driveId {
self.driveId = driveId
uid = File.uid(driveId: driveId, fileId: id)
}
rawType = "dir"
children = MutableSet<File>()
}
Expand Down

0 comments on commit 76339b3

Please sign in to comment.