diff options
Diffstat (limited to 'src/i_insert.go')
-rw-r--r-- | src/i_insert.go | 37 |
1 files changed, 35 insertions, 2 deletions
diff --git a/src/i_insert.go b/src/i_insert.go index 637f01f..5bc959c 100644 --- a/src/i_insert.go +++ b/src/i_insert.go @@ -87,7 +87,7 @@ func i_insert_format_filename(name, path string) string { } func i_insert_abs_files(insert *HostNode) { - files := [3]*string{ + files := []*string{ &insert.Priv, &insert.Jump.Priv, &insert.RDPFile, @@ -105,6 +105,19 @@ func i_insert_abs_files(insert *HostNode) { *v, _ = filepath.Abs(*v) } } + for k, v := range insert.Drive { + if len(v) > 0 { + if (v)[0] == '~' { + home_dir, err := os.UserHomeDir() + if err != nil { + return + } + v = home_dir + (v)[1:] + } + v, _ = filepath.Abs(v) + insert.Drive[k] = v + } + } } func i_insert_default_users(insert *HostNode) { @@ -124,6 +137,9 @@ func i_insert_default_users(insert *HostNode) { func i_insert_host(data *HardData, insert *HostNode) { i_insert_abs_files(insert) i_insert_default_users(insert) + if len(insert.Drive) == 0 { + insert.Drive = nil + } filename := i_insert_format_filename(insert.Name, data.data_dir + insert.parent.path()) insert.filename = filename @@ -207,7 +223,7 @@ func i_insert_check_ok(data *HardData, in *HostNode) { v = home_dir + v[1:] } if stat, err := os.Stat(v); - err != nil { + err != nil { data.insert_err = append(data.insert_err, errors.New(v + ": file does not exist")) } else if stat.IsDir() == true { @@ -216,6 +232,23 @@ func i_insert_check_ok(data *HardData, in *HostNode) { } } } + for _, v := range in.Drive { + if v[0] == '~' { + home_dir, err := os.UserHomeDir() + if err != nil { + return + } + v = home_dir + v[1:] + } + if stat, err := os.Stat(v); + err != nil { + data.insert_err = append(data.insert_err, errors.New(v + + ": path does not exist")) + } else if stat.IsDir() == false { + data.insert_err = append(data.insert_err, errors.New(v + + ": path is not a directory")) + } + } } func i_draw_tick_box(ui HardUI, line int, dim Quad, label string, content bool, |