diff --git a/drive/drive.go b/drive/drive.go index c012fab..fee3381 100644 --- a/drive/drive.go +++ b/drive/drive.go @@ -175,7 +175,7 @@ func (G *GoogleDriveClient) Download(nodeId string, localPath string, outputPath file := G.GetFileMetadata(nodeId) fmt.Printf("Name: %s, MimeType: %s\n", file.Name, file.MimeType) if outputPath == "" { - outputPath = file.Name + outputPath = utils.CleanupFilename(file.Name) } absPath := path.Join(localPath, outputPath) if file.MimeType == G.GDRIVE_DIR_MIMETYPE { @@ -202,7 +202,7 @@ func (G *GoogleDriveClient) Download(nodeId string, localPath string, outputPath func (G *GoogleDriveClient) TraverseNodes(nodeId string, localPath string) { files := G.GetFilesByParentId(nodeId) for _, file := range files { - absPath := path.Join(localPath, file.Name) + absPath := path.Join(localPath, utils.CleanupFilename(file.Name)) if file.MimeType == G.GDRIVE_DIR_MIMETYPE { err := os.MkdirAll(absPath, 0755) if err != nil { diff --git a/utils/utils.go b/utils/utils.go index 4c04c1d..1d28152 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -9,6 +9,7 @@ import ( "os" "path" "strconv" + "strings" "github.com/OpenPeeDeeP/xdg" "golang.org/x/oauth2" @@ -52,6 +53,9 @@ func fileExists(filename string) bool { if os.IsNotExist(err) { return false } + if info == nil { + return false + } return !info.IsDir() } @@ -98,3 +102,10 @@ func StringToInt(str string) (int, error) { } return i, nil } + +func CleanupFilename(name string) string { + for _, char := range []string{"\"", "?", "&", "*", "@", "!", "'"} { + name = strings.ReplaceAll(name, char, "") + } + return name +}