Skip to content

Commit

Permalink
chore: Merge branch 'master' into bump_dependency_
Browse files Browse the repository at this point in the history
  • Loading branch information
adrien-coye committed Aug 27, 2024
2 parents 3534fd9 + b692213 commit 79e5d61
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,9 @@ class SaveFileViewController: UIViewController {
@IBAction func close(_ sender: Any) {
importProgress?.cancel()
dismiss(animated: true)
if let extensionContext {
extensionContext.completeRequest(returningItems: nil, completionHandler: nil)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ class FileDetailActivityTableViewCell: InsetTableViewCell {
localizedKey = file.isDirectory ? "fileDetailsActivityFolderCreate" : "fileDetailsActivityFileCreate"
case .fileRename:
localizedKey = file.isDirectory ? "fileDetailsActivityFolderRename" : "fileDetailsActivityFileRename"
case .fileTrash:
case .fileTrash, .fileTrashInherited:
localizedKey = file.isDirectory ? "fileDetailsActivityFolderTrash" : "fileDetailsActivityFileTrash"
case .fileRestore:
case .fileRestore, .fileRestoreInherited:
localizedKey = file.isDirectory ? "fileDetailsActivityFolderRestore" : "fileDetailsActivityFileRestore"
case .fileDelete:
localizedKey = file.isDirectory ? "fileDetailsActivityFolderDelete" : "fileDetailsActivityFileDelete"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,16 @@ public extension DriveFileManager {
let fileUid = File.uid(driveId: directory.driveId, fileId: fileAction.fileId)

switch fileAction.action {
case .fileDelete, .fileTrash:
case .fileDelete, .fileTrash, .fileTrashInherited:
removeFileInDatabase(fileUid: fileUid, cascade: true, writableRealm: writableRealm)

case .fileMoveOut:
guard let movedOutFile: File = writableRealm.getObject(id: fileUid),
let oldParent = movedOutFile.parent else { continue }

oldParent.children.remove(movedOutFile)
case .fileMoveIn, .fileRestore, .fileCreate:

case .fileMoveIn, .fileRestore, .fileCreate, .fileRestoreInherited:
keepCacheAttributesForFile(
newFile: actionFile,
keepProperties: [.standard, .extras],
Expand All @@ -109,7 +110,10 @@ public extension DriveFileManager {
let oldParent = existingFile.parent {
oldParent.children.remove(existingFile)
}
directory.children.insert(actionFile)

if fileUid != directory.uid {
directory.children.insert(actionFile)
}

case .fileRename,
.fileFavoriteCreate, .fileUpdate, .fileFavoriteRemove,
Expand All @@ -129,8 +133,12 @@ public extension DriveFileManager {
writableRealm: writableRealm
)
writableRealm.add(actionFile, update: .modified)
directory.children.insert(actionFile)

if fileUid != directory.uid {
directory.children.insert(actionFile)
}
actionFile.applyLastModifiedDateToLocalFile()

default:
break
}
Expand Down
24 changes: 18 additions & 6 deletions kDriveCore/Data/Cache/DriveFileManager/DriveFileManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1018,19 +1018,31 @@ public final class DriveFileManager {
}

func removeFileInDatabase(fileUid: String, cascade: Bool, writableRealm: Realm) {
if let file = writableRealm.object(ofType: File.self, forPrimaryKey: fileUid), !file.isInvalidated {
var fileUidsToProcess = [fileUid]
var liveFilesToDelete = [File]()

while !fileUidsToProcess.isEmpty {
let currentFileUid = fileUidsToProcess.removeLast()
guard let file = writableRealm.object(ofType: File.self, forPrimaryKey: currentFileUid), !file.isInvalidated else {
continue
}

if fileManager.fileExists(atPath: file.localContainerUrl.path) {
try? fileManager.removeItem(at: file.localContainerUrl) // Check that it was correctly removed?
try? fileManager.removeItem(at: file.localContainerUrl)
}

if cascade {
for child in file.children.freeze() where !child.isInvalidated {
removeFileInDatabase(fileUid: child.uid, cascade: cascade, writableRealm: writableRealm)
let filesUidsToDelete = liveFilesToDelete.map { $0.uid }
let liveChildren = file.children.filter { child in
// A child should not be a circular reference to an ancestor
return !child.isInvalidated && !filesUidsToDelete.contains(child.uid)
}
fileUidsToProcess.append(contentsOf: liveChildren.map { $0.uid })
liveFilesToDelete.append(contentsOf: liveChildren)
}

writableRealm.delete(file)
}

writableRealm.delete(liveFilesToDelete)
}

private func deleteOrphanFiles(root: File..., newFiles: [File]? = nil, writableRealm: Realm) {
Expand Down
1 change: 1 addition & 0 deletions kDriveCore/Data/Models/File.swift
Original file line number Diff line number Diff line change
Expand Up @@ -842,6 +842,7 @@ extension File: Differentiable {
autoreleasepool {
lastModifiedAt == source.lastModifiedAt
&& sortedName == source.sortedName
&& name == source.name
&& isFavorite == source.isFavorite
&& isAvailableOffline == source.isAvailableOffline
&& visibility == source.visibility
Expand Down
3 changes: 3 additions & 0 deletions kDriveCore/Data/Models/FileActivity.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ public enum FileActivityType: String, Codable, CaseIterable {
case fileMoveIn = "file_move"
case fileMoveOut = "file_move_out"
case fileTrash = "file_trash"
case fileTrashInherited = "file_trash_inherited"
case fileRestore = "file_restore"
case fileRestoreInherited = "file_restore_inherited"
case fileDelete = "file_delete"
case fileUpdate = "file_update"
case fileCategorize = "file_categorize"
Expand Down Expand Up @@ -65,6 +67,7 @@ public enum FileActivityType: String, Codable, CaseIterable {
.fileMoveIn,
.fileMoveOut,
.fileTrash,
.fileTrashInherited,
.fileRestore,
.fileDelete,
.fileUpdate,
Expand Down

0 comments on commit 79e5d61

Please sign in to comment.