Skip to content

Commit

Permalink
logging and iCloud backup attribute fix
Browse files Browse the repository at this point in the history
  • Loading branch information
evermeer committed Dec 5, 2015
1 parent 443667f commit e6800ce
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 21 deletions.
2 changes: 1 addition & 1 deletion EVURLCache.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Pod::Spec.new do |s|
#

s.name = "EVURLCache"
s.version = "2.1.3"
s.version = "2.1.4"
s.summary = "NSURLCache subclass for handeling all web requests that use NSURLRequest"
s.description = "This is a NSURLCache subclass for handeling all web requests that use NSURLRequest. (This includes UIWebView)"
s.homepage = "https://github.com/evermeer/EVURLCache"
Expand Down
29 changes: 9 additions & 20 deletions EVURLCache/Pod/EVURLCache.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,14 @@ public class EVURLCache : NSURLCache {
NSURLCache.setSharedURLCache(urlCache)
}

// Output log messages if logging is enabled
private static func debugLog(message: String) {
// Log a message with info if enabled
public static func debugLog<T>(object: T, filename: String = __FILE__, line: Int = __LINE__, funcname: String = __FUNCTION__) {
if LOGGING {
NSLog(message)
let dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "MM/dd/yyyy HH:mm:ss:SSS"
let process = NSProcessInfo.processInfo()
let threadId = "." //NSThread.currentThread().threadDictionary
NSLog("\(dateFormatter.stringFromDate(NSDate())) \(process.processName))[\(process.processIdentifier):\(threadId)] \((filename as NSString).lastPathComponent)(\(line)) \(funcname):\r\t\(object)\n")
}
}

Expand Down Expand Up @@ -209,27 +213,12 @@ public class EVURLCache : NSURLCache {
return localUrl
}

// You don't want your cache to be backed up.
public static func addSkipBackupAttributeToItemAtURL(url: NSURL) -> Bool {
let bufLength = getxattr(url.absoluteString, "com.apple.MobileBackup", nil, 0, 0, 0)
if bufLength == -1 {
return false
} else {
let buf = malloc(bufLength)
let result = getxattr(url.absoluteString, "com.apple.MobileBackup", buf, bufLength, 0, 0)
if result == -1 {
return false
}
let removeResult = removexattr(url.absoluteString, "com.apple.MobileBackup", 0)
if removeResult == 0 {
debugLog("Removed extended attribute on file \(url)")
}
}
do {
try url.setResourceValue(NSNumber(bool: true), forKey: NSURLIsExcludedFromBackupKey)
return true
} catch {
debugLog("Unable to set SkipBackupAttributeToItemAtURL")
} catch _ as NSError {
debugLog("ERROR: Could not set 'exclude from backup' attribute for file \(url.absoluteString)")
}
return false
}
Expand Down

0 comments on commit e6800ce

Please sign in to comment.