Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lockfile fixes for LibreOffice #84

Merged
merged 11 commits into from
Jun 5, 2020
Prev Previous commit
Next Next commit
remove cache.DriveType() in favor of the API values
  • Loading branch information
jstaf committed Jun 5, 2020
commit f8adb8a3aeab1dadd74587184d9dcc87f5a5bdd8
19 changes: 0 additions & 19 deletions fs/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,25 +129,6 @@ func (c *Cache) IsOffline() bool {
return c.offline
}

// DriveType lazily fetches the OneDrive drivetype
func (c *Cache) DriveType() string {
c.RLock()
driveType := c.driveType
c.RUnlock()

if driveType == "" {
drive, err := graph.GetDrive(c.GetAuth())
if err == nil {
c.Lock()
c.driveType = drive.DriveType
c.Unlock()
return drive.DriveType
}
log.Error("Drivetype was empty and could not be fetched!")
}
return driveType
}

func leadingSlash(path string) string {
if !strings.HasPrefix(path, "/") {
path = "/" + path
Expand Down
2 changes: 1 addition & 1 deletion fs/delta_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
func (i *Inode) setContent(newContent []byte) {
i.DriveItem.Size = uint64(len(newContent))
i.data = &newContent
if fsCache.DriveType() == graph.DriveTypePersonal {
if i.DriveItem.Parent.DriveType == graph.DriveTypePersonal {
i.DriveItem.File.Hashes.SHA1Hash = graph.SHA1Hash(&newContent)
} else {
i.DriveItem.File.Hashes.QuickXorHash = graph.QuickXORHash(&newContent)
Expand Down
4 changes: 2 additions & 2 deletions fs/inode.go
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ func (i *Inode) Fsync(ctx context.Context, f fs.FileHandle, flags uint32) syscal

// recompute hashes when saving new content
i.DriveItem.File = &graph.File{}
if i.cache.DriveType() == graph.DriveTypePersonal {
if i.DriveItem.Parent.DriveType == graph.DriveTypePersonal {
i.DriveItem.File.Hashes.SHA1Hash = graph.SHA1Hash(i.data)
} else {
i.DriveItem.File.Hashes.QuickXorHash = graph.QuickXORHash(i.data)
Expand Down Expand Up @@ -799,11 +799,11 @@ func (i *Inode) Open(ctx context.Context, flags uint32) (fh fs.FileHandle, fuseF

// try grabbing from disk
cache := i.GetCache()
driveType := cache.DriveType()
if content := cache.GetContent(id); content != nil {
// verify content against what we're supposed to have
var hashMatch bool
i.mutex.RLock()
driveType := i.DriveItem.Parent.DriveType
if isLocalID(id) && i.DriveItem.File == nil {
// only check hashes if the file has been uploaded before, otherwise
// we just accept the cached content.
Expand Down