From 0d3ee4186c28caf4ecdcafc2dedd12d3b4b46b19 Mon Sep 17 00:00:00 2001 From: Gilbert Chen Date: Tue, 16 Jan 2024 12:50:59 -0500 Subject: [PATCH] Use a different api to find the id of a GCD drive by name Previous a listing api was used to find the id. That api only returns 10 drives for each call. If there are more than 10 shared drives some may not be returned. --- src/duplicacy_gcdstorage.go | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/src/duplicacy_gcdstorage.go b/src/duplicacy_gcdstorage.go index d7fea7b..bdf8f71 100644 --- a/src/duplicacy_gcdstorage.go +++ b/src/duplicacy_gcdstorage.go @@ -408,22 +408,21 @@ 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 + // In case the driveID is a name, convert it to an id + query := fmt.Sprintf("name='%s'", driveID) + driveList, err := drive.NewDrivesService(service).List().Q(query).Do() + if err == nil { + found := false + for _, drive := range driveList.Drives { + if drive.Name == driveID { + found = true + driveID = drive.Id + break + } + } + if !found { + return nil, fmt.Errorf("%s is not the id or name of a shared drive", driveID) } - } - - if !found { - return nil, fmt.Errorf("%s is not the id or name of a shared drive", driveID) } }