Skip to content

Commit d3f858e

Browse files
mzfrmzfr
authored andcommitted
Fix for #23
1 parent bcd9bed commit d3f858e

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

main.go

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,19 @@ func init() {
3535
}
3636
}
3737

38+
// Function to test if the given
39+
// directory/file exists or not
40+
func dirExist(path string) (bool, error) {
41+
_, err := os.Stat(path)
42+
if err == nil {
43+
return true, nil
44+
}
45+
if os.IsNotExist(err) {
46+
return false, nil
47+
}
48+
return false, err
49+
}
50+
3851
// list all the files of a given directory
3952
func visit(root string) ([]string, error) {
4053
var files []string
@@ -220,8 +233,16 @@ func main() {
220233

221234
for _, key := range paths.([]interface{}) {
222235
for _, file := range key.(map[interface{}]interface{}) {
223-
filePath := fmt.Sprintf("%s/%s", dir, file)
224-
fi, err := os.Stat(filePath)
236+
PathofFile := fmt.Sprintf("%s/%s", dir, file)
237+
checkDir, err := dirExist(PathofFile)
238+
if err != nil {
239+
fmt.Printf("Some issue with directories")
240+
continue
241+
}
242+
if checkDir == false {
243+
continue
244+
}
245+
fi, err := os.Stat(PathofFile)
225246
if err != nil {
226247
fmt.Println(err)
227248
return
@@ -232,7 +253,7 @@ func main() {
232253
switch mode := fi.Mode(); {
233254
case mode.IsRegular():
234255
doc := etree.NewDocument()
235-
if err := doc.ReadFromFile(filePath); err != nil {
256+
if err := doc.ReadFromFile(PathofFile); err != nil {
236257
panic(err)
237258
}
238259
// Parsing AndroidManifest for any API keys in there
@@ -252,12 +273,12 @@ func main() {
252273
}
253274
// Just listing files of raw and xml directory
254275
case mode.IsDir():
255-
if filepath.Base(filePath) == "xml" {
276+
if filepath.Base(PathofFile) == "xml" {
256277
fmt.Printf("%s:\n", "XML-files")
257278
} else {
258279
fmt.Printf("%s:\n", "raw-files")
259280
}
260-
files, err := visit(filePath)
281+
files, err := visit(PathofFile)
261282
if err != nil {
262283
fmt.Println(err)
263284
}

0 commit comments

Comments
 (0)