Commit e21f45f8 authored by Christopher Schinnerl's avatar Christopher Schinnerl

fix race condition

parent 2d4f6466
......@@ -222,6 +222,13 @@ func (sf *SiaFile) MasterKey() crypto.CipherKey {
return sk
}
// Metadata returns the metadata of the SiaFile.
func (sf *SiaFile) Metadata() Metadata {
sf.mu.RLock()
defer sf.mu.RUnlock()
return sf.staticMetadata
}
// Mode returns the FileMode of the SiaFile.
func (sf *SiaFile) Mode() os.FileMode {
sf.mu.RLock()
......
......@@ -147,7 +147,7 @@ func (sfs *SiaFileSet) closeEntry(entry *SiaFileSetEntry) {
// and then a new/different file was uploaded with the same siapath.
//
// If they are not the same entry, there is nothing more to do.
currentEntry := sfs.siaFileMap[entry.staticMetadata.StaticUniqueID]
currentEntry := sfs.siaFileMap[entry.Metadata().StaticUniqueID]
if currentEntry != entry.siaFileSetEntry {
return
}
......@@ -155,7 +155,7 @@ func (sfs *SiaFileSet) closeEntry(entry *SiaFileSetEntry) {
// If there are no more threads that have the current entry open, delete
// this entry from the set cache.
if len(currentEntry.threadMap) == 0 {
delete(sfs.siaFileMap, entry.staticMetadata.StaticUniqueID)
delete(sfs.siaFileMap, entry.Metadata().StaticUniqueID)
delete(sfs.siapathToUID, sfs.siaPath(entry.siaFileSetEntry))
}
}
......@@ -264,7 +264,7 @@ func (sfs *SiaFileSet) metadata(siaPath modules.SiaPath) (Metadata, error) {
entry, _, exists := sfs.siaPathToEntryAndUID(siaPath)
if exists {
// Get metadata from entry.
return entry.staticMetadata, nil
return entry.Metadata(), nil
}
// Try and Load Metadata from disk
md, err := LoadSiaFileMetadata(siaPath.SiaFileSysPath(sfs.siaFileDir))
......@@ -295,7 +295,7 @@ func (sfs *SiaFileSet) Delete(siaPath modules.SiaPath) error {
// Remove the siafile from the set maps so that other threads can't find
// it.
delete(sfs.siaFileMap, entry.staticMetadata.StaticUniqueID)
delete(sfs.siaFileMap, entry.Metadata().StaticUniqueID)
delete(sfs.siapathToUID, sfs.siaPath(entry.siaFileSetEntry))
return nil
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment