Skip to content

Commit

Permalink
persist origin file permission
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangduo committed May 8, 2020
1 parent e0e9772 commit bdde031
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 10 deletions.
4 changes: 2 additions & 2 deletions source/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ DEPENDENCIES:
- SwiftyJSON (~> 5.0)

SPEC REPOS:
https://github.com/CocoaPods/Specs.git:
https://github.com/cocoapods/specs.git:
- Alamofire
- SwiftyJSON

Expand All @@ -17,4 +17,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: 1e14da6108c97041b7daef307aaa48a8f180f7a4

COCOAPODS: 1.8.0
COCOAPODS: 1.7.5
8 changes: 4 additions & 4 deletions source/tinypng4mac.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -455,10 +455,10 @@
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = "$(inherited)";
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 10;
CURRENT_PROJECT_VERSION = 11;
INFOPLIST_FILE = tinypng4mac/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
MARKETING_VERSION = 1.0.3;
MARKETING_VERSION = 1.0.4;
PRODUCT_BUNDLE_IDENTIFIER = com.kyleduo.tinypngmac;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
Expand All @@ -472,10 +472,10 @@
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = "$(inherited)";
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 10;
CURRENT_PROJECT_VERSION = 11;
INFOPLIST_FILE = tinypng4mac/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
MARKETING_VERSION = 1.0.3;
MARKETING_VERSION = 1.0.4;
PRODUCT_BUNDLE_IDENTIFIER = com.kyleduo.tinypngmac;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
Expand Down
9 changes: 7 additions & 2 deletions source/tinypng4mac/MainViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,13 @@ class MainViewController: NSViewController, NSOpenSavePanelDelegate, NSTableView
print(file.filePath.path)
print(file.filePath.relativePath)
let attributes = try? manager.attributesOfItem(atPath: file.filePath.path)
let size = attributes![FileAttributeKey.size]!
let task = TPTaskInfo(file, originSize: (size as AnyObject).doubleValue!)
let size = (attributes![FileAttributeKey.size]! as AnyObject).doubleValue!
let permission = TPConfig.shouldReplace() ? attributes![FileAttributeKey.posixPermissions] as! NSNumber? : nil
let task = TPTaskInfo(
file,
originSize: size,
filePermission: permission
)
tasks.append(task)
}
TPClient.sharedClient.add(tasks)
Expand Down
4 changes: 3 additions & 1 deletion source/tinypng4mac/model/TPTaskInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class TPTaskInfo: NSObject {
var originFile: URL
var outputFile: URL?
var resultUrl: String
var filePermission: NSNumber
var fileInfo: FileInfo
var originSize: Double
var status: TPTaskStatus
Expand All @@ -22,7 +23,7 @@ class TPTaskInfo: NSObject {
var errorMessage: String?
var index: Int

init(_ fileInfo: FileInfo, originSize: Double) {
init(_ fileInfo: FileInfo, originSize: Double, filePermission: NSNumber?) {
self.originFile = fileInfo.filePath
self.fileInfo = fileInfo
self.originSize = originSize
Expand All @@ -37,6 +38,7 @@ class TPTaskInfo: NSObject {
self.uuid = UUID().uuidString
self.errorMessage = nil
self.index = 0
self.filePermission = filePermission != nil ? filePermission! : NSNumber(value: 0o644)
}

override var description: String {
Expand Down
2 changes: 1 addition & 1 deletion source/tinypng4mac/tpclient/TPClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ class TPClient {
self.updateStatus(task, newStatus: .finish)
debugPrint("finish: " + task.fileInfo.relativePath + " tasks: " + String(self.runningTasks))
do {
try FileManager.default.setAttributes([FileAttributeKey.posixPermissions: NSNumber(value: 0o644)], ofItemAtPath: task.fileInfo.filePath.path)
try FileManager.default.setAttributes([FileAttributeKey.posixPermissions: task.filePermission], ofItemAtPath: task.fileInfo.filePath.path)
} catch {
debugPrint("FileManager set posixPermissions error")
}
Expand Down

0 comments on commit bdde031

Please sign in to comment.