-
Notifications
You must be signed in to change notification settings - Fork 295
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
Hardlinks are dereferenced in generated archives #1896
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
21d309e
Hardlinks are dereferenced in generated archives
jjbustamante 9c53229
Apply suggestions from code review
jjbustamante 5f5f2af
Implementing the methods to detect hardlinks on windows
jjbustamante 16e645d
documenting new methods added
jjbustamante 3c598f4
fixing some feedback from review
jjbustamante 4738eb2
Merge branch 'main' into bugfix/jjbustamante/issue-1286
jjbustamante 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 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 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 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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
//go:build linux || darwin | ||
|
||
package archive | ||
|
||
import ( | ||
"os" | ||
"syscall" | ||
) | ||
|
||
// hasHardlinks check if the given files has a hard-link associated with it | ||
func hasHardlinks(fi os.FileInfo, path string) (bool, error) { | ||
return fi.Sys().(*syscall.Stat_t).Nlink > 1, nil | ||
} | ||
|
||
// getInodeFromStat returns the inode (index node) value associated with the given file | ||
func getInodeFromStat(stat interface{}, path string) (inode uint64, err error) { | ||
s, ok := stat.(*syscall.Stat_t) | ||
if ok { | ||
inode = s.Ino | ||
} | ||
return | ||
} |
This file contains 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 |
---|---|---|
@@ -0,0 +1,68 @@ | ||
//go:build windows | ||
|
||
package archive | ||
|
||
import ( | ||
"os" | ||
"syscall" | ||
|
||
"golang.org/x/sys/windows" | ||
) | ||
|
||
// hasHardlinks returns true if the given file has hard-links associated with it | ||
func hasHardlinks(fi os.FileInfo, path string) (bool, error) { | ||
var numberOfLinks uint32 | ||
switch v := fi.Sys().(type) { | ||
case *syscall.ByHandleFileInformation: | ||
numberOfLinks = v.NumberOfLinks | ||
default: | ||
// We need an instance of a ByHandleFileInformation to read NumberOfLinks | ||
info, err := open(path) | ||
if err != nil { | ||
return false, err | ||
} | ||
numberOfLinks = info.NumberOfLinks | ||
} | ||
return numberOfLinks > 1, nil | ||
} | ||
|
||
// getInodeFromStat returns an equivalent representation of unix inode on windows based on FileIndexHigh and FileIndexLow values | ||
func getInodeFromStat(stat interface{}, path string) (inode uint64, err error) { | ||
s, ok := stat.(*syscall.ByHandleFileInformation) | ||
if ok { | ||
inode = (uint64(s.FileIndexHigh) << 32) | uint64(s.FileIndexLow) | ||
} else { | ||
s, err = open(path) | ||
if err == nil { | ||
inode = (uint64(s.FileIndexHigh) << 32) | uint64(s.FileIndexLow) | ||
} | ||
} | ||
return | ||
} | ||
|
||
// open returns a ByHandleFileInformation object representation of the given file | ||
func open(path string) (*syscall.ByHandleFileInformation, error) { | ||
fPath, err := syscall.UTF16PtrFromString(path) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
handle, err := syscall.CreateFile( | ||
fPath, | ||
windows.FILE_READ_ATTRIBUTES, | ||
syscall.FILE_SHARE_READ|syscall.FILE_SHARE_WRITE|syscall.FILE_SHARE_DELETE, | ||
nil, | ||
syscall.OPEN_EXISTING, | ||
syscall.FILE_FLAG_BACKUP_SEMANTICS, | ||
0) | ||
if err != nil { | ||
return nil, err | ||
} | ||
defer syscall.CloseHandle(handle) | ||
|
||
var info syscall.ByHandleFileInformation | ||
if err = syscall.GetFileInformationByHandle(handle, &info); err != nil { | ||
return nil, err | ||
} | ||
return &info, nil | ||
} |
This file contains 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 |
---|---|---|
@@ -0,0 +1 @@ | ||
foo |
This file contains 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 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 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 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 |
---|---|---|
@@ -0,0 +1 @@ | ||
build-contents |
Empty file.
10 changes: 10 additions & 0 deletions
10
pkg/buildpack/testdata/buildpack-with-hardlink/buildpack.toml
This file contains 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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
api = "0.3" | ||
|
||
[buildpack] | ||
id = "bp.one" | ||
version = "1.2.3" | ||
homepage = "http://one.buildpack" | ||
|
||
[[stacks]] | ||
id = "some.stack.id" | ||
mixins = ["mixinX", "build:mixinY", "run:mixinZ"] |
This file contains 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 |
---|---|---|
@@ -0,0 +1 @@ | ||
foo |
This file contains 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.
I noticed this line could throw the same error reported here