Skip to content

Commit

Permalink
set browsignpaths folder to readonly
Browse files Browse the repository at this point in the history
  • Loading branch information
AO3\andriws.luna committed May 30, 2024
1 parent ac7fe16 commit a871697
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
8 changes: 4 additions & 4 deletions utils/librarypath/dproj_itil.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
}
}

Expand Down
27 changes: 25 additions & 2 deletions utils/librarypath/librarypath.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
package librarypath

import (
"fmt"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
"regexp"
"strings"

"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"
)

Expand Down Expand Up @@ -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()

Expand All @@ -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)
}
}

}

}
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit a871697

Please sign in to comment.