From 89ec7eb0fb3d46fd585404b2904442a1c3e3d0a9 Mon Sep 17 00:00:00 2001 From: Caleb Gardner Date: Wed, 16 Dec 2020 02:39:35 -0600 Subject: [PATCH] Fixed GetSymlinkFile Added GetSymlinkFileRecursive --- file.go | 26 ++++++++++++++++++++++++-- squash_test.go | 2 +- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/file.go b/file.go index 0ad1beb..d5aec36 100644 --- a/file.go +++ b/file.go @@ -229,7 +229,8 @@ func (f *File) SymlinkPath() string { } } -//GetSymlinkFile tries to return the squashfs.File associated with the symlink +//GetSymlinkFile tries to return the squashfs.File associated with the symlink. If the file isn't a symlink +//or the symlink points to a location outside the archive, nil is returned. func (f *File) GetSymlinkFile() *File { if !f.IsSymlink() { return nil @@ -237,7 +238,28 @@ func (f *File) GetSymlinkFile() *File { if strings.HasSuffix(f.SymlinkPath(), "/") { return nil } - return f.r.GetFileAtPath(f.SymlinkPath()) + return f.Parent.GetFileAtPath(f.SymlinkPath()) +} + +//GetSymlinkFileRecursive tries to return the squasfs.File associated with the symlink. It will recursively +//try to get the symlink's file. This will return either a non-symlink File, or nil. +func (f *File) GetSymlinkFileRecursive() *File { + if !f.IsSymlink() { + return nil + } + if strings.HasSuffix(f.SymlinkPath(), "/") { + return nil + } + sym := f + for { + sym = sym.GetSymlinkFile() + if sym == nil { + return nil + } + if !sym.IsSymlink() { + return sym + } + } } //Mode returns the os.FileMode of the File. Sets mode bits for directories and symlinks. diff --git a/squash_test.go b/squash_test.go index 350b886..f1a6ae9 100644 --- a/squash_test.go +++ b/squash_test.go @@ -78,7 +78,7 @@ func downloadTestAppImage(t *testing.T, dir string) { } defer appImage.Close() check := http.Client{ - CheckRedirect: func(r *http.Request, via []*http.Request) error { + CheckRedirect: func(r *http.Request, _ []*http.Request) error { r.URL.Opaque = r.URL.Path return nil },