Skip to content
This repository has been archived by the owner on Oct 14, 2024. It is now read-only.

Commit

Permalink
set root home if exists when getting home user dirs
Browse files Browse the repository at this point in the history
  • Loading branch information
FrimIdan committed Aug 30, 2023
1 parent 90f54e5 commit 9bfae09
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pkg/shared/families/infofinder/sshtopology/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,13 @@ func (s *Scanner) Run(sourceType utils.SourceType, userInput string) error {

func getHomeUserDirs(rootDir string) ([]string, error) {
var dirs []string

// Set root home if exists.
rootHome := path.Join(rootDir, "root")
if _, err := os.Stat(rootHome); err == nil {
dirs = append(dirs, rootHome)
}

homeDirPath := path.Join(rootDir, "home")
files, err := os.ReadDir(homeDirPath)
if err != nil {
Expand Down
8 changes: 8 additions & 0 deletions pkg/shared/families/infofinder/sshtopology/scanner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ func Test_getHomeUserDirs(t *testing.T) {
want: []string{"../testdata/rootfolder/home/dir1", "../testdata/rootfolder/home/dir2"},
wantErr: false,
},
{
name: "root folder with root home folder",
args: args{
rootDir: "../testdata/rootfolderwithroothome",
},
want: []string{"../testdata/rootfolderwithroothome/root", "../testdata/rootfolderwithroothome/home/dir1", "../testdata/rootfolderwithroothome/home/dir2"},
wantErr: false,
},
{
name: "missing dir",
args: args{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-----BEGIN OPENSSH PRIVATE KEY-----
NOT REALLY A KEY
-----END OPENSSH PRIVATE KEY-----
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-----BEGIN OPENSSH PRIVATE KEY-----
NOT REALLY A KEY
-----END OPENSSH PRIVATE KEY-----
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-----BEGIN OPENSSH PRIVATE KEY-----
NOT REALLY A KEY
-----END OPENSSH PRIVATE KEY-----

0 comments on commit 9bfae09

Please sign in to comment.