aboutsummaryrefslogtreecommitdiffstats
path: root/drive/download.go
diff options
context:
space:
mode:
authorPetter Rasmussen2016-01-17 23:12:26 +0100
committerPetter Rasmussen2016-01-17 23:12:26 +0100
commitd4d1b00c9609a4d493f79bdd74bae5dc60d37ed7 (patch)
treef54e38bf8654ce3deab9691acbfe3df6a5d438da /drive/download.go
parentc88aba0d9b14777be0915541503ca0e1a7936f67 (diff)
downloadgdrive-d4d1b00c9609a4d493f79bdd74bae5dc60d37ed7.tar.bz2
Return error
Diffstat (limited to 'drive/download.go')
-rw-r--r--drive/download.go25
1 files changed, 17 insertions, 8 deletions
diff --git a/drive/download.go b/drive/download.go
index 9a35912..57e0160 100644
--- a/drive/download.go
+++ b/drive/download.go
@@ -13,43 +13,52 @@ type DownloadFileArgs struct {
Stdout bool
}
-func (self *Drive) Download(args DownloadFileArgs) {
+func (self *Drive) Download(args DownloadFileArgs) (err error) {
getFile := self.service.Files.Get(args.Id)
f, err := getFile.Do()
- errorF(err, "Failed to get file: %s", err)
+ if err != nil {
+ return fmt.Errorf("Failed to get file: %s", err)
+ }
res, err := getFile.Download()
- errorF(err, "Failed to download file: %s", err)
+ if err != nil {
+ return fmt.Errorf("Failed to download file: %s", err)
+ }
// Close body on function exit
defer res.Body.Close()
if args.Stdout {
// Write file content to stdout
- io.Copy(os.Stdout, res.Body)
- return
+ _, err := io.Copy(os.Stdout, res.Body)
+ return err
}
// Check if file exists
if !args.Force && fileExists(f.Name) {
- exitF("File '%s' already exists, use --force to overwrite", f.Name)
+ return fmt.Errorf("File '%s' already exists, use --force to overwrite", f.Name)
}
// Create new file
outFile, err := os.Create(f.Name)
- errorF(err, "Unable to create new file: %s", err)
+ if err != nil {
+ return fmt.Errorf("Unable to create new file: %s", err)
+ }
// Close file on function exit
defer outFile.Close()
// Save file to disk
bytes, err := io.Copy(outFile, res.Body)
- errorF(err, "Failed saving file: %s", err)
+ if err != nil {
+ return fmt.Errorf("Failed saving file: %s", err)
+ }
fmt.Printf("Downloaded '%s' at %s, total %d\n", f.Name, "x/s", bytes)
//if deleteSourceFile {
// self.Delete(args.Id)
//}
+ return
}