fix: implement dirlfs to ignore symlinks
This commit is contained in:
@ -11,7 +11,7 @@
|
|||||||
<g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11">
|
<g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11">
|
||||||
<text x="33.5" y="15" fill="#010101" fill-opacity=".3">coverage</text>
|
<text x="33.5" y="15" fill="#010101" fill-opacity=".3">coverage</text>
|
||||||
<text x="33.5" y="14">coverage</text>
|
<text x="33.5" y="14">coverage</text>
|
||||||
<text x="86" y="15" fill="#010101" fill-opacity=".3">19.8%</text>
|
<text x="86" y="15" fill="#010101" fill-opacity=".3">19.9%</text>
|
||||||
<text x="86" y="14">19.8%</text>
|
<text x="86" y="14">19.9%</text>
|
||||||
</g>
|
</g>
|
||||||
</svg>
|
</svg>
|
||||||
|
Before Width: | Height: | Size: 926 B After Width: | Height: | Size: 926 B |
53
internal/shutils/helpers/dirlfs.go
Normal file
53
internal/shutils/helpers/dirlfs.go
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
// ALR - Any Linux Repository
|
||||||
|
// Copyright (C) 2025 The ALR Authors
|
||||||
|
//
|
||||||
|
// This program is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
package helpers
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io/fs"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
)
|
||||||
|
|
||||||
|
// dirLfs implements fs.FS like os.DirFS but uses LStat instead of Stat.
|
||||||
|
// This means symbolic links are treated as links themselves rather than
|
||||||
|
// being followed to their targets.
|
||||||
|
type dirLfs struct {
|
||||||
|
fs.FS
|
||||||
|
dir string
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewDirLFS(dir string) *dirLfs {
|
||||||
|
return &dirLfs{
|
||||||
|
FS: os.DirFS(dir),
|
||||||
|
dir: dir,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *dirLfs) Stat(name string) (fs.FileInfo, error) {
|
||||||
|
if !fs.ValidPath(name) {
|
||||||
|
return nil, &fs.PathError{Op: "stat", Path: name, Err: fs.ErrInvalid}
|
||||||
|
}
|
||||||
|
|
||||||
|
fullPath := filepath.Join(d.dir, filepath.FromSlash(name))
|
||||||
|
|
||||||
|
info, err := os.Lstat(fullPath)
|
||||||
|
if err != nil {
|
||||||
|
return nil, &fs.PathError{Op: "stat", Path: name, Err: err}
|
||||||
|
}
|
||||||
|
|
||||||
|
return info, nil
|
||||||
|
}
|
@ -160,7 +160,7 @@ func filesFindCmd(hc interp.HandlerContext, cmd string, args []string) error {
|
|||||||
searchPath := path.Join(hc.Dir, globPattern)
|
searchPath := path.Join(hc.Dir, globPattern)
|
||||||
|
|
||||||
basepath, pattern := doublestar.SplitPattern(searchPath)
|
basepath, pattern := doublestar.SplitPattern(searchPath)
|
||||||
fsys := os.DirFS(basepath)
|
fsys := NewDirLFS(basepath)
|
||||||
matches, err := doublestar.Glob(fsys, pattern, doublestar.WithNoFollow(), doublestar.WithFailOnPatternNotExist())
|
matches, err := doublestar.Glob(fsys, pattern, doublestar.WithNoFollow(), doublestar.WithFailOnPatternNotExist())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("files-find: glob pattern error: %w", err)
|
return fmt.Errorf("files-find: glob pattern error: %w", err)
|
||||||
|
@ -236,6 +236,7 @@ func TestFindFiles(t *testing.T) {
|
|||||||
"opt/app",
|
"opt/app",
|
||||||
"opt/app/internal",
|
"opt/app/internal",
|
||||||
"opt/app/with space",
|
"opt/app/with space",
|
||||||
|
"usr/bin",
|
||||||
},
|
},
|
||||||
filesToCreate: []string{
|
filesToCreate: []string{
|
||||||
"usr/share/locale/ru/LC_MESSAGES/yandex-disk.mo",
|
"usr/share/locale/ru/LC_MESSAGES/yandex-disk.mo",
|
||||||
@ -249,6 +250,10 @@ func TestFindFiles(t *testing.T) {
|
|||||||
linkPath: "/opt/app/etc",
|
linkPath: "/opt/app/etc",
|
||||||
targetPath: "/etc",
|
targetPath: "/etc",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
linkPath: "/usr/bin/file",
|
||||||
|
targetPath: "/not-existing",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
expectedOutput: []string{
|
expectedOutput: []string{
|
||||||
"./usr/share/locale/ru/LC_MESSAGES/yandex-disk.mo",
|
"./usr/share/locale/ru/LC_MESSAGES/yandex-disk.mo",
|
||||||
@ -259,8 +264,9 @@ func TestFindFiles(t *testing.T) {
|
|||||||
"./opt/app/internal/test",
|
"./opt/app/internal/test",
|
||||||
"./opt/app/with space",
|
"./opt/app/with space",
|
||||||
"./opt/app/with space/file",
|
"./opt/app/with space/file",
|
||||||
|
"./usr/bin/file",
|
||||||
},
|
},
|
||||||
args: "\"/usr/share/locale/*/LC_MESSAGES/*.mo\" \"/opt/app/**/*\"",
|
args: "\"/usr/share/locale/*/LC_MESSAGES/*.mo\" \"/opt/app/**/*\" \"/usr/bin/file\"",
|
||||||
expectedError: nil,
|
expectedError: nil,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user