From 41e3d8119ff42d9dbaf0a53272741978f80d6318 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=95=D0=B2=D0=B3=D0=B5=D0=BD=D0=B8=D0=B9=20=D0=A5=D1=80?= =?UTF-8?q?=D0=B0=D0=BC=D0=BE=D0=B2?= Date: Thu, 25 Sep 2025 22:10:47 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D1=8B=20files-find:=20systemd,=20systemd-user,=20license?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 4 +- internal/shutils/helpers/files_find.go | 105 +++++++++++++++++++++++++ internal/shutils/helpers/helpers.go | 44 ++++++----- 3 files changed, 133 insertions(+), 20 deletions(-) diff --git a/.gitignore b/.gitignore index 6b4d30c..0a4426d 100644 --- a/.gitignore +++ b/.gitignore @@ -11,4 +11,6 @@ e2e-tests/alr CLAUDE.md -commit_msg.txt \ No newline at end of file +commit_msg.txt +/scripts/.claude/settings.local.json +/ALR diff --git a/internal/shutils/helpers/files_find.go b/internal/shutils/helpers/files_find.go index 570fb8f..1a704f9 100644 --- a/internal/shutils/helpers/files_find.go +++ b/internal/shutils/helpers/files_find.go @@ -402,3 +402,108 @@ func filesFindConfigCmd(hc interp.HandlerContext, cmd string, args []string) err return outputFiles(hc, configFiles) } + +func filesFindSystemdCmd(hc interp.HandlerContext, cmd string, args []string) error { + namePattern := "*" + if len(args) > 0 { + namePattern = args[0] + } + + systemdPath := "./usr/lib/systemd/system/" + realPath := path.Join(hc.Dir, systemdPath) + + if err := validateDir(realPath, "files-find-systemd"); err != nil { + return err + } + + var systemdFiles []string + err := filepath.Walk(realPath, func(p string, info os.FileInfo, err error) error { + if err != nil { + return err + } + + if !info.IsDir() && matchNamePattern(info.Name(), namePattern) { + relPath, relErr := makeRelativePath(hc.Dir, p) + if relErr != nil { + return relErr + } + systemdFiles = append(systemdFiles, relPath) + } + return nil + }) + if err != nil { + return fmt.Errorf("files-find-systemd: %w", err) + } + + return outputFiles(hc, systemdFiles) +} + +func filesFindSystemdUserCmd(hc interp.HandlerContext, cmd string, args []string) error { + namePattern := "*" + if len(args) > 0 { + namePattern = args[0] + } + + systemdUserPath := "./usr/lib/systemd/user/" + realPath := path.Join(hc.Dir, systemdUserPath) + + if err := validateDir(realPath, "files-find-systemd-user"); err != nil { + return err + } + + var systemdUserFiles []string + err := filepath.Walk(realPath, func(p string, info os.FileInfo, err error) error { + if err != nil { + return err + } + + if !info.IsDir() && matchNamePattern(info.Name(), namePattern) { + relPath, relErr := makeRelativePath(hc.Dir, p) + if relErr != nil { + return relErr + } + systemdUserFiles = append(systemdUserFiles, relPath) + } + return nil + }) + if err != nil { + return fmt.Errorf("files-find-systemd-user: %w", err) + } + + return outputFiles(hc, systemdUserFiles) +} + +func filesFindLicenseCmd(hc interp.HandlerContext, cmd string, args []string) error { + namePattern := "*" + if len(args) > 0 { + namePattern = args[0] + } + + licensePath := "./usr/share/licenses/" + realPath := path.Join(hc.Dir, licensePath) + + if err := validateDir(realPath, "files-find-license"); err != nil { + return err + } + + var licenseFiles []string + err := filepath.Walk(realPath, func(p string, info os.FileInfo, err error) error { + if err != nil { + return err + } + + if !info.IsDir() && matchNamePattern(info.Name(), namePattern) { + relPath, relErr := makeRelativePath(hc.Dir, p) + if relErr != nil { + return relErr + } + licenseFiles = append(licenseFiles, relPath) + } + return nil + }) + if err != nil { + return fmt.Errorf("files-find-license: %w", err) + } + + return outputFiles(hc, licenseFiles) +} diff --git a/internal/shutils/helpers/helpers.go b/internal/shutils/helpers/helpers.go index c39b310..65b43ac 100644 --- a/internal/shutils/helpers/helpers.go +++ b/internal/shutils/helpers/helpers.go @@ -56,30 +56,36 @@ var Helpers = handlers.ExecFuncs{ "install-library": installLibraryCmd, "git-version": gitVersionCmd, - "files-find": filesFindCmd, - "files-find-lang": filesFindLangCmd, - "files-find-doc": filesFindDocCmd, - "files-find-bin": filesFindBinCmd, - "files-find-lib": filesFindLibCmd, - "files-find-include": filesFindIncludeCmd, - "files-find-share": filesFindShareCmd, - "files-find-man": filesFindManCmd, - "files-find-config": filesFindConfigCmd, + "files-find": filesFindCmd, + "files-find-lang": filesFindLangCmd, + "files-find-doc": filesFindDocCmd, + "files-find-bin": filesFindBinCmd, + "files-find-lib": filesFindLibCmd, + "files-find-include": filesFindIncludeCmd, + "files-find-share": filesFindShareCmd, + "files-find-man": filesFindManCmd, + "files-find-config": filesFindConfigCmd, + "files-find-systemd": filesFindSystemdCmd, + "files-find-systemd-user": filesFindSystemdUserCmd, + "files-find-license": filesFindLicenseCmd, } // Restricted contains restricted read-only helper commands // that don't modify any state var Restricted = handlers.ExecFuncs{ - "git-version": gitVersionCmd, - "files-find": filesFindCmd, - "files-find-lang": filesFindLangCmd, - "files-find-doc": filesFindDocCmd, - "files-find-bin": filesFindBinCmd, - "files-find-lib": filesFindLibCmd, - "files-find-include": filesFindIncludeCmd, - "files-find-share": filesFindShareCmd, - "files-find-man": filesFindManCmd, - "files-find-config": filesFindConfigCmd, + "git-version": gitVersionCmd, + "files-find": filesFindCmd, + "files-find-lang": filesFindLangCmd, + "files-find-doc": filesFindDocCmd, + "files-find-bin": filesFindBinCmd, + "files-find-lib": filesFindLibCmd, + "files-find-include": filesFindIncludeCmd, + "files-find-share": filesFindShareCmd, + "files-find-man": filesFindManCmd, + "files-find-config": filesFindConfigCmd, + "files-find-systemd": filesFindSystemdCmd, + "files-find-systemd-user": filesFindSystemdUserCmd, + "files-find-license": filesFindLicenseCmd, } func installHelperCmd(prefix string, perms os.FileMode) handlers.ExecFunc {