Skip to content

Commit

Permalink
Merge pull request #1198 from Infomaniak/fix_importFromExtensionFolde…
Browse files Browse the repository at this point in the history
…rUsage

fix: FileImportHelper use the dedicated import folder, not group app folder
  • Loading branch information
adrien-coye committed Jun 12, 2024
2 parents 9fe83f6 + 41d762a commit 00c609b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
20 changes: 14 additions & 6 deletions kDrive/UI/Controller/Files/Save File/SaveFileViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,14 @@ class SaveFileViewController: UIViewController {
assetIdentifiers,
userPreferredPhotoFormat: userPreferredPhotoFormat
) { [weak self] importedFiles, errorCount in
self?.items = importedFiles
self?.errorCount = errorCount
guard let self else {
return
}

items = importedFiles
self.errorCount = errorCount
Task { @MainActor in
self?.updateTableViewAfterImport()
self.updateTableViewAfterImport()
}
}
}
Expand All @@ -222,10 +226,14 @@ class SaveFileViewController: UIViewController {
importProgress = fileImportHelper
.importItems(itemProviders,
userPreferredPhotoFormat: userPreferredPhotoFormat) { [weak self] importedFiles, errorCount in
self?.items = importedFiles
self?.errorCount = errorCount
guard let self else {
return
}

items = importedFiles
self.errorCount = errorCount
Task { @MainActor in
self?.updateTableViewAfterImport()
self.updateTableViewAfterImport()
}
}
}
Expand Down
10 changes: 6 additions & 4 deletions kDriveCore/Utils/Files/FileImportHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public final class FileImportHelper {
var finalUrl: URL
if self.appContextService.isExtension {
// In extension, we need to copy files to a path within appGroup to be able to upload from the main app.
let appGroupURL = try URL.appGroupUniqueFolderURL()
let appGroupURL = try URL.appGroupImportUniqueFolderURL()

// Get import URL
let appGroupFileURL = appGroupURL.appendingPathComponent(fileName)
Expand Down Expand Up @@ -249,7 +249,7 @@ public final class FileImportHelper {
var finalUrl: URL
if self.appContextService.isExtension {
// In extension, we need to copy files to a path within appGroup to be able to upload from the main app.
let appGroupURL = try URL.appGroupUniqueFolderURL()
let appGroupURL = try URL.appGroupImportUniqueFolderURL()

// Get import URL
let appGroupFileURL = appGroupURL.appendingPathComponent(fileName)
Expand Down Expand Up @@ -281,10 +281,12 @@ public final class FileImportHelper {
// TODO: move to core
extension URL {
/// Build a path where a file can be moved within the appGroup while preventing collisions
static func appGroupUniqueFolderURL() throws -> URL {
///
/// Uses the importDirectoryURL, that exists within the appGroup, to allow for easy cleaning.
static func appGroupImportUniqueFolderURL() throws -> URL {
// Use a unique folder to prevent collisions
@InjectService var pathProvider: AppGroupPathProvidable
let targetFolderURL = pathProvider.groupDirectoryURL
let targetFolderURL = pathProvider.importDirectoryURL
.appendingPathComponent(UUID().uuidString, isDirectory: true)
try FileManager.default.createDirectory(at: targetFolderURL, withIntermediateDirectories: true)
return targetFolderURL
Expand Down

0 comments on commit 00c609b

Please sign in to comment.