Skip to content

Commit 236e2cb

Browse files
committed
https://github.com/golang/go/issues/16582
1 parent 43b011b commit 236e2cb

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

main.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ func main() {
4242
// Authentication is provided by the gcloud tool when running locally, and
4343
// by the associated service account when running on Compute Engine.
4444
client, err := google.DefaultClient(context.Background(), scope)
45+
4546
if err != nil {
4647
log.Fatalf("Unable to get default client: %v", err)
4748
}
@@ -63,15 +64,23 @@ func main() {
6364
storageservice.SetCurrentStorageAccessor(accessor)
6465

6566
// read the pdfs in pdf directory
66-
files, err := ioutil.ReadDir(*localDir)
67+
allfiles, err := ioutil.ReadDir(*localDir)
6768
if err != nil {
6869
log.Fatal(err)
6970
}
7071

72+
// take top 100 since
73+
// https://github.com/golang/go/issues/16582
74+
maxcount := len(allfiles)
75+
if maxcount > 100 {
76+
maxcount = 100
77+
}
78+
files := allfiles[:maxcount]
79+
7180
var wg sync.WaitGroup
7281
wg.Add(len(files))
7382
// one month ago
74-
timeThreshold := time.Now().AddDate(0, 0, -1)
83+
timeThreshold := time.Now().AddDate(0, -1, 0)
7584

7685
for _, file := range files {
7786
// shrink the files older than one month

storageservice/storageaccessor.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@ func (accessor *StorageAccessor) Move(service *storage.Service, shortfilename st
6060
// great, unlink the localfile
6161
os.Remove(longfilename)
6262
return true
63+
} else {
64+
fatalf("Objects.Insert failed: %v", err)
65+
return false
6366
}
64-
65-
fatalf("Objects.Insert failed: %v", err)
66-
return false
6767
}
6868

6969
// Copy copy localfile to storage
@@ -98,4 +98,4 @@ func (accessor *StorageAccessor) Copy(service *storage.Service, shortfilename st
9898

9999
fatalf("Objects.Insert failed: %v", err)
100100
return false
101-
}
101+
}

0 commit comments

Comments
 (0)