From 79d8654a12236f1567dfba20db05c1be15550fc4 Mon Sep 17 00:00:00 2001 From: Gilbert Chen Date: Wed, 8 Apr 2020 23:59:15 -0400 Subject: [PATCH] Allow the name of Google Shared Drive to be used in the storage url The previous PR only accepts the id of the shared drive, which is not very memorable. This commit makes it able to specify the drive by id or by name. --- src/duplicacy_gcdstorage.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/duplicacy_gcdstorage.go b/src/duplicacy_gcdstorage.go index 72487bd..02cc1b8 100644 --- a/src/duplicacy_gcdstorage.go +++ b/src/duplicacy_gcdstorage.go @@ -367,6 +367,24 @@ func CreateGCDStorage(tokenFile string, driveID string, storagePath string, thre if len(driveID) == 0 { driveID = GCDUserDrive + } else { + driveList, err := drive.NewTeamdrivesService(service).List().Do() + if err != nil { + return nil, fmt.Errorf("Failed to look up the drive id: %v", err) + } + + found := false + for _, teamDrive := range driveList.TeamDrives { + if teamDrive.Id == driveID || teamDrive.Name == driveID { + driveID = teamDrive.Id + found = true + break + } + } + + if !found { + return nil, fmt.Errorf("%s is not the id or name of a shared drive", driveID) + } } storage = &GCDStorage{