You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: backup/hasher.go
+3-9Lines changed: 3 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -48,9 +48,7 @@ func (s *BackupSession) hashOneFile(plan HashPlan) {
48
48
log.Println("Updating fs_modifed in db so next time I don't reread this for no reason lol")
49
49
// this is VERY uncommon, so it is NOT worth maintaining a db WRITE transaction for it sadly
50
50
_, err:=db.DB.Exec("UPDATE files SET fs_modified = ?, permissions = ? WHERE path = ? AND end IS NULL", info.ModTime().Unix(), info.Mode()&os.ModePerm, path)
51
-
iferr!=nil {
52
-
panic(err)
53
-
}
51
+
db.Must(err)
54
52
return
55
53
}
56
54
@@ -64,18 +62,14 @@ func (s *BackupSession) hashOneFile(plan HashPlan) {
64
62
s.hashLateMapLock.Lock() // this lock ensures atomicity between the hashLateMap, and the database (blob_entries and files)
65
63
defers.hashLateMapLock.Unlock()
66
64
tx, err:=db.DB.Begin()
67
-
iferr!=nil {
68
-
panic(err)
69
-
}
65
+
db.Must(err)
70
66
defertx.Rollback() // fileHasKnownData can panic
71
67
vardbHash []byte
72
68
err=tx.QueryRow("SELECT hash FROM blob_entries WHERE hash = ?", hash).Scan(&dbHash)
73
69
iferr==nil {
74
70
// yeah so we already have this hash backed up, so the train stops here. we just need to add this to files table, and we're done!
txCommitted=true// err on the side of caution - if tx.Commit returns an err, very likely it did not actually commit, but, it's possible! so don't delete the blob if there's ANY chance that the db is expecting this blob to exist.
186
-
err=tx.Commit()
187
-
iferr!=nil {
188
-
panic(err)
189
-
}
176
+
db.Must(tx.Commit())
190
177
log.Println("Committed uploaded blob")
191
178
}
192
179
193
180
func (s*BackupSession) fileHasKnownData(tx*sql.Tx, pathstring, info os.FileInfo, hash []byte) {
194
181
// important to use the same "now" for both of these queries, so that the file's history is presented without "gaps" (that could be present if we called time.Now() twice in a row)
195
182
_, err:=tx.Exec("UPDATE files SET end = ? WHERE path = ? AND end IS NULL", s.now, path)
196
-
iferr!=nil {
197
-
panic(err)
198
-
}
183
+
db.Must(err)
199
184
modTime:=info.ModTime().Unix()
200
185
ifmodTime<0 {
201
186
panic(fmt.Sprintf("Invalid modification time for %s: %d", path, modTime))
0 commit comments