From a87169701f5eefe1a18304a8321bc00c7dee9403 Mon Sep 17 00:00:00 2001 From: "AO3\\andriws.luna" Date: Thu, 30 May 2024 18:32:56 -0300 Subject: [PATCH] set browsignpaths folder to readonly --- utils/librarypath/dproj_itil.go | 8 ++++---- utils/librarypath/librarypath.go | 27 +++++++++++++++++++++++++-- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/utils/librarypath/dproj_itil.go b/utils/librarypath/dproj_itil.go index f395b89..088bc99 100644 --- a/utils/librarypath/dproj_itil.go +++ b/utils/librarypath/dproj_itil.go @@ -92,7 +92,7 @@ func createTagOtherUnitFiles(node *etree.Element) *etree.Element { return child } -func updateGlobalBrowsingByProject(dprojName string) { +func updateGlobalBrowsingByProject(dprojName string, setReadOnly bool) { ideVersion := bossRegistry.GetCurrentDelphiVersion() if ideVersion == "" { msg.Err("Version not found for path %s", env.GlobalConfiguration.DelphiPath) @@ -126,7 +126,7 @@ func updateGlobalBrowsingByProject(dprojName string) { splitPaths := strings.Split(paths, ";") rootPath := filepath.Join(env.GetCurrentDir(), path.Dir(dprojName)) - newSplitPaths := GetNewBrowsingPaths(splitPaths, false, rootPath) + newSplitPaths := GetNewBrowsingPaths(splitPaths, false, rootPath, setReadOnly) newPaths := strings.Join(newSplitPaths, ";") err = delphiPlatform.SetStringValue(BrowsingPathRegistry, newPaths) utils.HandleError(err) @@ -136,9 +136,9 @@ func updateGlobalBrowsingByProject(dprojName string) { func updateGlobalBrowsingPath(pkg *models.Package) { var isLazarus = isLazarus() var projectNames = GetProjectNames(pkg) - for _, projectName := range projectNames { + for i, projectName := range projectNames { if !isLazarus { - updateGlobalBrowsingByProject(projectName) + updateGlobalBrowsingByProject(projectName, i == 0) } } diff --git a/utils/librarypath/librarypath.go b/utils/librarypath/librarypath.go index e8a6c61..73ba1ba 100644 --- a/utils/librarypath/librarypath.go +++ b/utils/librarypath/librarypath.go @@ -1,8 +1,10 @@ package librarypath import ( + "fmt" "io/ioutil" "os" + "os/exec" "path/filepath" "regexp" "strings" @@ -10,6 +12,7 @@ import ( "github.com/hashload/boss/consts" "github.com/hashload/boss/env" "github.com/hashload/boss/models" + "github.com/hashload/boss/msg" "github.com/hashload/boss/utils" ) @@ -41,7 +44,7 @@ func cleanPath(paths []string, fullPath bool) []string { return processedPaths } -func GetNewBrowsingPaths(paths []string, fullPath bool, rootPath string) []string { +func GetNewBrowsingPaths(paths []string, fullPath bool, rootPath string, setReadOnly bool) []string { paths = cleanPath(paths, fullPath) var path = env.GetModulesDir() @@ -54,7 +57,26 @@ func GetNewBrowsingPaths(paths []string, fullPath bool, rootPath string) []strin other, _ := models.LoadPackageOther(packagePath) if other.BrowsingPath != "" { - paths = getNewBrowsingPathsFromDir(filepath.Join(path, value.Name(), other.BrowsingPath), paths, fullPath, rootPath) + dir := filepath.Join(path, value.Name(), other.BrowsingPath) + paths = getNewBrowsingPathsFromDir(dir, paths, fullPath, rootPath) + + if setReadOnly { + readonlybat := filepath.Join(dir, "readonly.bat") + readFileStr := fmt.Sprintf(`attrib +r "%s" /s /d`, filepath.Join(dir, "*")) + err = ioutil.WriteFile(readonlybat, []byte(readFileStr), os.ModePerm) + if err != nil { + msg.Warn(" - error on create build file") + } + + cmd := exec.Command(readonlybat) + + if _, err := cmd.Output(); err != nil { + msg.Err(" - Failed to set readonly property to folder", dir, " - ", err) + } else { + os.Remove(readonlybat) + } + } + } } @@ -131,6 +153,7 @@ func getNewBrowsingPathsFromDir(path string, paths []string, fullPath bool, root matched, _ := regexp.MatchString(consts.RegexArtifacts, info.Name()) if matched { dir, _ := filepath.Split(path) + if !fullPath { dir, _ = filepath.Rel(rootPath, dir) }