Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
martenrebane committed Jun 12, 2024
1 parent f4d142d commit 03db08c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
16 changes: 8 additions & 8 deletions MoppApp/MoppApp/FileManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -311,13 +311,13 @@ class MoppFileManager {

func removeFile(withPath filePath: String) {
let filePathURL = URL(fileURLWithPath: filePath)
guard filePathURL.isValidPath() else {
guard let validFilePathURL = filePathURL.getValidPath(), validFilePathURL.isValidPath() else {
printLog("Unable to remove file. Invalid path: \(filePathURL.path)")
return
}

do {
try fileManager.removeItem(atPath: filePath)
try fileManager.removeItem(atPath: validFilePathURL.path)
} catch {
printLog("removeFileWithPath error: \(error.localizedDescription)")
}
Expand All @@ -333,11 +333,11 @@ class MoppFileManager {

func fileExists(_ sourcePath: String) -> Bool {
let sourcePathURL = URL(fileURLWithPath: sourcePath)
guard sourcePathURL.isValidPath() else {
guard let validSourcePathURL = sourcePathURL.getValidPath(), validSourcePathURL.isValidPath() else {
printLog("Unable to check if file exists. Invalid path: \(sourcePathURL.path)")
return false
}
return fileManager.fileExists(atPath: sourcePath)
return fileManager.fileExists(atPath: validSourcePathURL.path)
}

func directoryExists(_ sourcePath: String) -> Bool {
Expand All @@ -349,15 +349,15 @@ class MoppFileManager {
func moveFile(withPath sourcePath: String, toPath destinationPath: String, overwrite: Bool) -> Bool {
let sourcePathURL = URL(fileURLWithPath: sourcePath)
let destinationPathURL = URL(fileURLWithPath: destinationPath)
guard sourcePathURL.isValidPath() && destinationPathURL.isValidPath() else {
guard let validSourcePathURL = sourcePathURL.getValidPath(), let validDestinationPathURL = destinationPathURL.getValidPath(), validSourcePathURL.isValidPath() && validDestinationPathURL.isValidPath() else {
printLog("Unable to move file to destination. Invalid path: \(sourcePathURL.path) or \(destinationPathURL.path)")
return false
}
if overwrite && fileExists(destinationPath) {
removeFile(withPath: destinationPath)
if overwrite && fileExists(validDestinationPathURL.path) {
removeFile(withPath: validDestinationPathURL.path)
}
do {
try fileManager.moveItem(atPath: sourcePath, toPath: destinationPath)
try fileManager.moveItem(atPath: validSourcePathURL.path, toPath: validDestinationPathURL.path)
} catch {
printLog("moveFileWithPath error: \(error.localizedDescription)")
return false
Expand Down
12 changes: 6 additions & 6 deletions MoppApp/MoppApp/MimeTypeExtractor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -185,22 +185,22 @@ class MimeTypeExtractor {
}

private static func removeUnzippedFolder(folderPath: URL) -> Void {
guard folderPath.isValidPath() else {
guard let validFolderPath = folderPath.getValidPath(), validFolderPath.isValidPath() else {
printLog("Unable to remove unzipped folder. Invalid path: \(folderPath.path)")
return
}

MoppFileManager().removeFile(withPath: folderPath.path)
MoppFileManager().removeFile(withPath: validFolderPath.path)
}

private static func isDdoc(url: URL) -> Bool {
guard url.isValidPath() else {
guard let validUrl = url.getValidPath(), validUrl.isValidPath() else {
printLog("Unable to check if file is DDOC container. Invalid path: \(url.path)")
return false
}

do {
let fileData = try Data(contentsOf: url)
let fileData = try Data(contentsOf: validUrl)
guard !fileData.isEmpty else {
return false
}
Expand All @@ -223,13 +223,13 @@ class MimeTypeExtractor {
}

private static func isCdoc(url: URL) -> Bool {
guard url.isValidPath() else {
guard let validUrl = url.getValidPath(), url.isValidPath() else {
printLog("Unable to check if file is CDOC container. Invalid path: \(url.path)")
return false
}

do {
let fileData = try Data(contentsOf: url)
let fileData = try Data(contentsOf: validUrl)
guard !fileData.isEmpty else {
return false
}
Expand Down
12 changes: 6 additions & 6 deletions MoppApp/MoppApp/MoppApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ class MoppApp: UIApplication, URLSessionDelegate, URLSessionDownloadDelegate {
return false
}
let newData: Data? = try Data(contentsOf: validUrl)
let fileName: String = newUrl.deletingPathExtension().lastPathComponent.sanitize()
let fileName: String = validUrl.deletingPathExtension().lastPathComponent.sanitize()
let tempDirectoryPath: URL? = MoppFileManager.shared.tempCacheDirectoryPath()
guard let tempDirectory = tempDirectoryPath else {
printLog("Unable to get temporary file directory")
Expand All @@ -348,7 +348,7 @@ class MoppApp: UIApplication, URLSessionDelegate, URLSessionDownloadDelegate {
return false
}
try newUrlData.write(to: validUrl, options: .atomic)
newUrl = filePath
newUrl = validUrl
if !isFileEmpty {
fileUrls.append(newUrl)
}
Expand All @@ -375,14 +375,14 @@ class MoppApp: UIApplication, URLSessionDelegate, URLSessionDownloadDelegate {
newUrl.deletePathExtension()
newUrl.appendPathExtension(ContainerFormatCdoc)
}
guard let validUrl = newUrl.getValidPath(), validUrl.isValidPath() else {
guard let validUrl = url.getValidPath(), let validNewUrl = newUrl.getValidPath(), validUrl.isValidPath(), validNewUrl.isValidPath() else {
printLog("Unable to move file. Invalid path: \(newUrl.path)")
return false
}
let isFileMoved = MoppFileManager.shared.moveFile(withPath: url.path, toPath: newUrl.path, overwrite: true)
let isFileMoved = MoppFileManager.shared.moveFile(withPath: validUrl.path, toPath: validNewUrl.path, overwrite: true)
if !isFileMoved {
newUrl = url
fileUrls.append(newUrl)
newUrl = validUrl
fileUrls.append(validNewUrl)
}
}
}
Expand Down

0 comments on commit 03db08c

Please sign in to comment.