-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add fetch-interval to outdated
command to skip fetching the dependencies
#2714
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,13 +22,12 @@ public struct FetchCache { | |
lastFetchTimes.removeAll() | ||
} | ||
|
||
internal static func needsFetch(forURL url: GitURL) -> Bool { | ||
guard let lastFetch = lastFetchTimes[url] else { | ||
internal static func needsFetch(forURL url: GitURL) -> Bool { | ||
guard let lastFetch = lastFetchTimes[url] ?? repositoriesLastFetchTime() else { | ||
return true | ||
} | ||
|
||
let difference = Date().timeIntervalSince1970 - lastFetch | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you please revert this change? |
||
return !(0...fetchCacheInterval).contains(difference) | ||
} | ||
|
||
|
@@ -37,6 +36,52 @@ public struct FetchCache { | |
lastFetchTimes[url] = Date().timeIntervalSince1970 | ||
} | ||
} | ||
|
||
fileprivate static func repositoriesLastFetchTime() -> TimeInterval? { | ||
guard let data = try? Constants.Dependency.repositoriesURL.extendedAttribute(for: "\(Constants.bundleIdentifier).repositories.last.fetch.time") else { | ||
return nil | ||
} | ||
return data.withUnsafeBytes { $0.pointee as TimeInterval } | ||
} | ||
|
||
public static func updateRepositoriesLastFetchTime() { | ||
var now = Date().timeIntervalSince1970 | ||
let data = Data(bytes: &now, count: MemoryLayout<TimeInterval>.size) | ||
try? Constants.Dependency.repositoriesURL.setExtendedAttribute(for: "\(Constants.bundleIdentifier).repositories.last.fetch.time", data: data) | ||
} | ||
} | ||
|
||
/// URL extension to support operations on extended attributes of a file | ||
fileprivate extension URL { | ||
|
||
enum ExtendedAttributesError: Error { | ||
case cannotReadAttribute | ||
case cannotSetAttribute | ||
} | ||
|
||
func extendedAttribute(for name: String) throws -> Data { | ||
let data = try withUnsafeFileSystemRepresentation { path -> Data in | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Curious -- what are your thoughts on using this approach rather than using the methods provided by https://developer.apple.com/documentation/foundation/filemanager/1413667-setattributes https://developer.apple.com/documentation/foundation/filemanager/1410452-attributesofitem |
||
let length = getxattr(path, name, nil, 0, 0, 0) | ||
guard length >= 0 else { throw ExtendedAttributesError.cannotReadAttribute } | ||
|
||
var data = Data(count: length) | ||
let result = data.withUnsafeMutableBytes { [count = data.count] in | ||
getxattr(path, name, $0.baseAddress, count, 0, 0) | ||
} | ||
guard result >= 0 else { throw ExtendedAttributesError.cannotReadAttribute } | ||
return data | ||
} | ||
return data | ||
} | ||
|
||
func setExtendedAttribute(for name: String, data: Data) throws { | ||
try withUnsafeFileSystemRepresentation { path in | ||
let result = data.withUnsafeBytes { | ||
setxattr(path, name, $0, data.count, 0, 0) | ||
} | ||
guard result >= 0 else { throw ExtendedAttributesError.cannotSetAttribute } | ||
} | ||
} | ||
} | ||
|
||
/// Shells out to `git` with the given arguments, optionally in the directory | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Carthage uses tabs instead of spaces for indentation -- could you please reformat your changes to do the same?