Skip to content

Commit

Permalink
Merge pull request #63 from CryoByte33/cleanup-find-symlinks
Browse files Browse the repository at this point in the history
Fix bug causing symlinks to not display in the cleanup function
  • Loading branch information
CryoByte33 committed Feb 23, 2023
2 parents 7fde922 + 16c5d3b commit 37b2ba1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
32 changes: 19 additions & 13 deletions internal/handler_game_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type DataToMove struct {
}

// Get a list of the directories inside the provided directory, ignoring symbolic links
func getDirectoryList(path string) ([]string, error) {
func getDirectoryList(path string, includeSymlinks bool) ([]string, error) {
var folderList []string
// Get a list of all files in directory
files, err := os.ReadDir(path)
Expand All @@ -36,10 +36,16 @@ func getDirectoryList(path string) ([]string, error) {
for _, file := range files {
// ui.CryoUtils.InfoLog.Println(file.Name())
// Create a full path with the file and path names
fullPath := path + "/" + file.Name()
// If the file is a directory AND is NOT a symlink, append the name of the folder to the list
if file.IsDir() && !isSymbolicLink(fullPath) {
folderList = append(folderList, file.Name())
fullPath := filepath.Join(path, file.Name())
if !includeSymlinks {
// If the file is a directory AND is NOT a symlink, append the name of the folder to the list
if file.IsDir() && !isSymbolicLink(fullPath) {
folderList = append(folderList, file.Name())
}
} else {
if file.IsDir() {
folderList = append(folderList, file.Name())
}
}
}

Expand All @@ -50,11 +56,11 @@ func getDirectoryList(path string) ([]string, error) {
func (s *StorageStatus) getStorageStatus(left string, right string) error {
var err error
if left == SteamDataRoot {
s.LeftCompatDirectories, err = getDirectoryList(SteamCompatRoot)
s.LeftCompatDirectories, err = getDirectoryList(SteamCompatRoot, false)
if err != nil {
return err
}
s.LeftShaderDirectories, err = getDirectoryList(SteamShaderRoot)
s.LeftShaderDirectories, err = getDirectoryList(SteamShaderRoot, false)
if err != nil {
return err
}
Expand All @@ -64,22 +70,22 @@ func (s *StorageStatus) getStorageStatus(left string, right string) error {
// Create the directories if they don't exist already
_ = os.MkdirAll(compat, 0777)
_ = os.MkdirAll(shader, 0777)
s.LeftCompatDirectories, err = getDirectoryList(compat)
s.LeftCompatDirectories, err = getDirectoryList(compat, false)
if err != nil {
return err
}
s.LeftShaderDirectories, err = getDirectoryList(shader)
s.LeftShaderDirectories, err = getDirectoryList(shader, false)
if err != nil {
return err
}
}

if right == SteamDataRoot {
s.RightCompatDirectories, err = getDirectoryList(SteamCompatRoot)
s.RightCompatDirectories, err = getDirectoryList(SteamCompatRoot, false)
if err != nil {
return err
}
s.RightShaderDirectories, err = getDirectoryList(SteamShaderRoot)
s.RightShaderDirectories, err = getDirectoryList(SteamShaderRoot, false)
if err != nil {
return err
}
Expand All @@ -89,11 +95,11 @@ func (s *StorageStatus) getStorageStatus(left string, right string) error {
// Create the directories if they don't exist already
_ = os.MkdirAll(compat, 0777)
_ = os.MkdirAll(shader, 0777)
s.RightCompatDirectories, err = getDirectoryList(compat)
s.RightCompatDirectories, err = getDirectoryList(compat, false)
if err != nil {
return err
}
s.RightShaderDirectories, err = getDirectoryList(shader)
s.RightShaderDirectories, err = getDirectoryList(shader, false)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions internal/ui_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,14 @@ func createGameDataList() (*widget.CheckGroup, error) {

// Crawl the compat path and append the folders
// Append if no error, to prevent crashing for users that haven't synced data first.
dir, _ := getDirectoryList(compat)
dir, _ := getDirectoryList(compat, true)
if err == nil {
storage = append(storage, dir...)
}

// Crawl the shader path and append the folders
// Append if no error, to prevent crashing for users that haven't synced data first.
dir, _ = getDirectoryList(shader)
dir, _ = getDirectoryList(shader, true)
if err == nil {
storage = append(storage, dir...)
}
Expand Down

0 comments on commit 37b2ba1

Please sign in to comment.