88
88
func lookupTargetDir (ctx context.Context , dir string ) error {
89
89
const loopTimeout = 5 * time .Second
90
90
91
- l .Infoln ("Looking for target directory..." )
91
+ cleanDir := filepath .Clean (filepath .FromSlash (dir ))
92
+
93
+ l .Infoln ("Looking for target directory... %s" , cleanDir )
92
94
for {
93
95
// This block checks if stop signal is received from user
94
96
// and stops further lookup
@@ -98,20 +100,25 @@ func lookupTargetDir(ctx context.Context, dir string) error {
98
100
default :
99
101
}
100
102
101
- fInfo , err := os .Stat (dir )
102
- if err != nil && ! os .IsNotExist (err ) {
103
- return fmt .Errorf ("Target path %s exists but there is an error: %w" , dir , err )
104
- }
105
- if os .IsNotExist (err ) {
106
- time .Sleep (loopTimeout )
107
- continue
103
+ fInfo , err := os .Stat (cleanDir )
104
+ if err != nil {
105
+ if os .IsNotExist (err ) {
106
+ time .Sleep (loopTimeout )
107
+ continue
108
+ }
109
+ // Log the specific error type to help diagnose issues
110
+ return fmt .Errorf ("error accessing path %s (error type: %T): %w" , dir , err , err )
108
111
}
109
112
110
113
if ! fInfo .IsDir () {
111
- return fmt .Errorf ("Was expecting directory at %s, but found a file" , dir )
114
+ return fmt .Errorf ("was expecting directory at %s, but found a file" , dir )
115
+ }
116
+
117
+ abs , err := filepath .Abs (cleanDir )
118
+ if err != nil {
119
+ return fmt .Errorf ("failed to get absolute path for %s: %w" , dir , err )
112
120
}
113
121
114
- abs , _ := filepath .Abs (dir )
115
122
l .Infof ("Target directory found at %s" , abs )
116
123
break
117
124
}
0 commit comments