diff --git a/download.go b/download.go index c43d669..7936220 100644 --- a/download.go +++ b/download.go @@ -182,6 +182,18 @@ func syncHierarchyDown(driveBasePath string, localBasePath string, trustTimes bo uniqueDriveFiles = files } + // Warn that we're going to ignore any files that have slashes in their + // names. + var files []*gdrive.File + for _, f := range uniqueDriveFiles { + if f.PathHasSlash() { + message("%s: skipping file with slash in filename", f.Path) + } else { + files = append(files, f) + } + } + uniqueDriveFiles = files + // Create a map that stores the local filename to use for each file in // Google Drive. This map is indexed by the path of the Google Drive // file. diff --git a/gdrive/gdrive.go b/gdrive/gdrive.go index 209b82f..15ca655 100644 --- a/gdrive/gdrive.go +++ b/gdrive/gdrive.go @@ -69,6 +69,8 @@ const metadataVersion = 2 type File struct { // Path name on Drive. Does not start with a slash. Path string + // Indicates whether the original file name in Drive had a slash in it. + pathHasSlash bool // Size of the file in bytes. FileSize int64 // Unique id of the file (that persists over file modifications, @@ -137,6 +139,10 @@ func (f *File) driveFile() *drive.File { } } +func (f *File) PathHasSlash() bool { + return f.pathHasSlash +} + // IsFolder returns a boolean indicating whether the given File is a // folder. func (f *File) IsFolder() bool { @@ -559,11 +565,15 @@ func (gd *GDrive) UpdateMetadataCache(filename string) error { // declaration for an issue with this approach, though. file := new(File) *file = *f + file.pathHasSlash = strings.ContainsRune(f.Path, '/') file.Path = p gd.pathToFile[p] = append(gd.pathToFile[p], file) - dir := filepath.Dir(p) + // Explicitly trim off the file's name to get the path, rather + // than using filepath.Dir(), so that if there is a slash in + // the filename, we still get the expected result. + dir := filepath.Clean(strings.TrimSuffix(p, f.Path)) gd.dirToFiles[dir] = append(gd.dirToFiles[dir], file) if f.IsFolder() {