Repository navigation
Honour SOURCE_DATE_EPOCH for reproducible builds #176
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
Open
krishnapermi
wants to merge
6
commits into
apple:main
Choose a base branch
from
krishnapermi:honour-source-date-epoch
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
70fef63
Add mtime parameter to Archive public append functions
krishnapermi 9e4540b
Fix typo in project name comment
krishnapermi e61f3d3
Add mtime parameter to Archive+appending extension functions
krishnapermi 4b244fb
Honour SOURCE_DATE_EPOCH in publish: pass mtime to archive layers and…
krishnapermi 0c66895
Pass SOURCE_DATE_EPOCH through to containertool helper environment
krishnapermi 31e578c
Merge branch 'main' into honour-source-date-epoch
euanh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,80 +20,83 @@ import struct Foundation.URL | |
| import Tar | ||
|
|
||
| extension URL { | ||
| var isDirectory: Bool { | ||
| (try? resourceValues(forKeys: [.isDirectoryKey]))?.isDirectory == true | ||
| } | ||
| var isDirectory: Bool { | ||
|
Collaborator
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. Please don't reindent the code. There is an automated formatting check which won't pass unless the indentation is consistent. |
||
| (try? resourceValues(forKeys: [.isDirectoryKey]))?.isDirectory == true | ||
| } | ||
| } | ||
|
|
||
| extension Archive { | ||
| /// Append a file or directory tree to the archive. Directory trees are appended recursively. | ||
| /// Parameters: | ||
| /// - root: The path to the file or directory to add. | ||
| /// Returns: A new archive made by appending `root` to the receiver. | ||
| public func appendingRecursively(atPath root: String) throws -> Self { | ||
| let url = URL(fileURLWithPath: root) | ||
| if url.isDirectory { | ||
| return try self.appendingDirectoryTree(at: url) | ||
| } else { | ||
| return try self.appendingFile(at: url) | ||
| /// Append a file or directory tree to the archive. Directory trees are appended recursively. | ||
| /// Parameters: | ||
| /// - root: The path to the file or directory to add. | ||
| /// - mtime: Modification time for all entries as seconds since the Unix epoch (default: 0). | ||
| /// Returns: A new archive made by appending `root` to the receiver. | ||
| public func appendingRecursively(atPath root: String, mtime: Int = 0) throws -> Self { | ||
| let url = URL(fileURLWithPath: root) | ||
| if url.isDirectory { | ||
| return try self.appendingDirectoryTree(at: url, mtime: mtime) | ||
| } else { | ||
| return try self.appendingFile(at: url, mtime: mtime) | ||
| } | ||
| } | ||
|
|
||
| /// Append a single file to the archive. | ||
| /// Parameters: | ||
| /// - path: The path to the file to add. | ||
| /// - mtime: Modification time as seconds since the Unix epoch (default: 0). | ||
| /// Returns: A new archive made by appending `path` to the receiver. | ||
| func appendingFile(at path: URL, mtime: Int = 0) throws -> Self { | ||
| try self.appendingFile(name: path.lastPathComponent, data: try [UInt8](Data(contentsOf: path)), mtime: mtime) | ||
| } | ||
| } | ||
|
|
||
| /// Append a single file to the archive. | ||
| /// Parameters: | ||
| /// - path: The path to the file to add. | ||
| /// Returns: A new archive made by appending `path` to the receiver. | ||
| func appendingFile(at path: URL) throws -> Self { | ||
| try self.appendingFile(name: path.lastPathComponent, data: try [UInt8](Data(contentsOf: path))) | ||
| } | ||
| func appendingFile(at path: URL, to destinationPath: URL, mtime: Int = 0) throws -> Self { | ||
| var ret = self | ||
| let data = try [UInt8](Data(contentsOf: path)) | ||
| let components = destinationPath.pathComponents | ||
| precondition(!components.isEmpty, "Destination path is empty") | ||
| for i in 1..<components.count - 1 { | ||
| let directoryPath = components[..<i].joined(separator: "/") | ||
| try ret.appendDirectory(name: directoryPath, mtime: mtime) | ||
| } | ||
|
|
||
| func appendingFile(at path: URL, to destinationPath: URL) throws -> Self { | ||
| var ret = self | ||
| let data = try [UInt8](Data(contentsOf: path)) | ||
| let components = destinationPath.pathComponents | ||
| precondition(!components.isEmpty, "Destination path is empty") | ||
| for i in 1..<components.count - 1 { | ||
| let directoryPath = components[..<i].joined(separator: "/") | ||
| try ret.appendDirectory(name: directoryPath) | ||
| try ret.appendFile(name: destinationPath.path(), data: data, mtime: mtime) | ||
| return ret | ||
| } | ||
|
|
||
| try ret.appendFile(name: destinationPath.path(), data: data) | ||
| return ret | ||
| } | ||
| /// Recursively append a single directory tree to the archive. | ||
| /// Parameters: | ||
| /// - root: The path to the directory to add. | ||
| /// - mtime: Modification time for all entries as seconds since the Unix epoch (default: 0). | ||
| /// Returns: A new archive made by appending `root` to the receiver. | ||
| func appendingDirectoryTree(at root: URL, to destinationPath: URL = URL(filePath: "/"), mtime: Int = 0) throws -> Self { | ||
| var ret = self | ||
|
|
||
| /// Recursively append a single directory tree to the archive. | ||
| /// Parameters: | ||
| /// - root: The path to the directory to add. | ||
| /// Returns: A new archive made by appending `root` to the receiver. | ||
| func appendingDirectoryTree(at root: URL, to destinationPath: URL = URL(filePath: "/")) throws -> Self { | ||
| var ret = self | ||
| guard let enumerator = FileManager.default.enumerator(atPath: root.path) else { | ||
| throw ("Unable to read \(root.path)") | ||
| } | ||
|
|
||
| guard let enumerator = FileManager.default.enumerator(atPath: root.path) else { | ||
| throw ("Unable to read \(root.path)") | ||
| } | ||
| for case let subpath as String in enumerator { | ||
| // https://developer.apple.com/documentation/foundation/filemanager/1410452-attributesofitem | ||
| // https://developer.apple.com/documentation/foundation/fileattributekey | ||
|
|
||
| for case let subpath as String in enumerator { | ||
| // https://developer.apple.com/documentation/foundation/filemanager/1410452-attributesofitem | ||
| // https://developer.apple.com/documentation/foundation/fileattributekey | ||
| guard let filetype = enumerator.fileAttributes?[.type] as? FileAttributeType else { | ||
| throw ("Unable to get file type for \(subpath)") | ||
| } | ||
|
|
||
| guard let filetype = enumerator.fileAttributes?[.type] as? FileAttributeType else { | ||
| throw ("Unable to get file type for \(subpath)") | ||
| } | ||
| let subpath = destinationPath.appending(path: subpath).path() | ||
| switch filetype { | ||
| case .typeRegular: | ||
| let resource = try [UInt8](Data(contentsOf: root.appending(path: subpath))) | ||
| try ret.appendFile(name: subpath, prefix: root.lastPathComponent, data: resource, mtime: mtime) | ||
|
|
||
| let subpath = destinationPath.appending(path: subpath).path() | ||
| switch filetype { | ||
| case .typeRegular: | ||
| let resource = try [UInt8](Data(contentsOf: root.appending(path: subpath))) | ||
| try ret.appendFile(name: subpath, prefix: root.lastPathComponent, data: resource) | ||
| case .typeDirectory: | ||
| try ret.appendDirectory(name: subpath, prefix: root.lastPathComponent, mtime: mtime) | ||
|
|
||
| case .typeDirectory: | ||
| try ret.appendDirectory(name: subpath, prefix: root.lastPathComponent) | ||
| default: | ||
| throw "Resource file \(subpath) of type \(filetype) is not supported" | ||
| } | ||
| } | ||
|
|
||
| default: | ||
| throw "Resource file \(subpath) of type \(filetype) is not supported" | ||
| } | ||
| return ret | ||
| } | ||
|
|
||
| return ret | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
mtimemust come beforeprefix.