@@ -685,7 +685,7 @@ func (dh *DirHandle) ReadDir(internalOffset int, offset fuseops.DirOffset) (en *
685685 childTmp := parent .dir .Children [i ]
686686 if childTmp .AttrTime .Before (parent .dir .refreshStartTime ) &&
687687 atomic .LoadInt32 (& childTmp .fileHandles ) == 0 &&
688- atomic .LoadInt32 (& childTmp .CacheState ) == ST_CACHED &&
688+ atomic .LoadInt32 (& childTmp .CacheState ) <= ST_DEAD &&
689689 (! childTmp .isDir () || atomic .LoadInt64 (& childTmp .dir .ModifiedChildren ) == 0 ) {
690690 childTmp .mu .Lock ()
691691 notifications = append (notifications , & fuseops.NotifyDelete {
@@ -1043,7 +1043,7 @@ func (inode *Inode) SendDelete() {
10431043 }
10441044 forget := false
10451045 if inode .CacheState == ST_DELETED {
1046- inode .SetCacheState (ST_CACHED )
1046+ inode .SetCacheState (ST_DEAD )
10471047 // We don't remove directories until all children are deleted
10481048 // So that we don't revive the directory after removing it
10491049 // by fetching a list of files not all of which are actually deleted
@@ -1313,14 +1313,21 @@ func (inode *Inode) doUnlink() {
13131313 } else if inode .CacheState != ST_CREATED || inode .IsFlushing > 0 {
13141314 // resetCache will clear all buffers and abort the multipart upload
13151315 inode .resetCache ()
1316- inode .SetCacheState (ST_DELETED )
1317- if parent .dir .DeletedChildren == nil {
1318- parent .dir .DeletedChildren = make (map [string ]* Inode )
1316+ if parent .dir .DeletedChildren == nil || parent .dir .DeletedChildren [inode .Name ] == nil {
1317+ inode .SetCacheState (ST_DELETED )
1318+ if parent .dir .DeletedChildren == nil {
1319+ parent .dir .DeletedChildren = make (map [string ]* Inode )
1320+ }
1321+ parent .dir .DeletedChildren [inode .Name ] = inode
1322+ } else {
1323+ // A deleted file is already present, we can just reset the cache
1324+ inode .SetCacheState (ST_DEAD )
13191325 }
1320- parent .dir .DeletedChildren [inode .Name ] = inode
13211326 } else {
13221327 inode .resetCache ()
1328+ inode .SetCacheState (ST_DEAD )
13231329 }
1330+ inode .Attributes .Size = 0
13241331
13251332 parent .removeChildUnlocked (inode )
13261333}
@@ -1522,7 +1529,9 @@ func renameInCache(fromInode *Inode, newParent *Inode, to string) {
15221529 if parent .dir .DeletedChildren == nil {
15231530 parent .dir .DeletedChildren = make (map [string ]* Inode )
15241531 }
1525- parent .dir .DeletedChildren [fromInode .Name ] = fromInode
1532+ if parent .dir .DeletedChildren [fromInode .Name ] == nil {
1533+ parent .dir .DeletedChildren [fromInode .Name ] = fromInode
1534+ }
15261535 fromInode .renamingTo = false
15271536 } else {
15281537 parent .addModified (- 1 )
@@ -1538,7 +1547,9 @@ func renameInCache(fromInode *Inode, newParent *Inode, to string) {
15381547 if parent .dir .DeletedChildren == nil {
15391548 parent .dir .DeletedChildren = make (map [string ]* Inode )
15401549 }
1541- parent .dir .DeletedChildren [fromInode .Name ] = fromInode
1550+ if parent .dir .DeletedChildren [fromInode .Name ] == nil {
1551+ parent .dir .DeletedChildren [fromInode .Name ] = fromInode
1552+ }
15421553 if fromInode .CacheState == ST_CACHED {
15431554 // Was not modified and we remove it from current parent => add modified
15441555 parent .addModified (1 )
@@ -1637,7 +1648,7 @@ func (parent *Inode) insertSubTree(path string, obj *BlobItemOutput, dirs map[*I
16371648 }
16381649 } else if ! inode .isDir () {
16391650 // replace unmodified file item with a directory
1640- if atomic .LoadInt32 (& inode .CacheState ) == ST_CACHED {
1651+ if atomic .LoadInt32 (& inode .CacheState ) <= ST_DEAD {
16411652 inode .mu .Lock ()
16421653 atomic .StoreInt32 (& inode .refreshed , - 1 )
16431654 parent .removeChildUnlocked (inode )
0 commit comments