Skip to content

Commit 673e851

Browse files
committed
keep track of when changes need to be propagated
1 parent 6cdfa57 commit 673e851

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

ipnsfs/file.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ type file struct {
3434
ref int
3535
wref bool
3636

37+
hasChanges bool
38+
3739
mod *mod.DagModifier
3840
}
3941

@@ -53,6 +55,7 @@ func NewFile(name string, node *dag.Node, parent childCloser, fs *Filesystem) (*
5355
}
5456

5557
func (fi *file) Write(b []byte) (int, error) {
58+
fi.hasChanges = true
5659
return fi.mod.Write(b)
5760
}
5861

@@ -61,7 +64,7 @@ func (fi *file) Read(b []byte) (int, error) {
6164
}
6265

6366
func (fi *file) Close() error {
64-
if fi.mod.HasChanges() {
67+
if fi.hasChanges {
6568
err := fi.mod.Flush()
6669
if err != nil {
6770
return err
@@ -71,6 +74,8 @@ func (fi *file) Close() error {
7174
if err != nil {
7275
return err
7376
}
77+
78+
fi.hasChanges = false
7479
}
7580

7681
return nil
@@ -92,6 +97,7 @@ func (fi *file) Seek(offset int64, whence int) (int64, error) {
9297
}
9398

9499
func (fi *file) WriteAt(b []byte, at int64) (int, error) {
100+
fi.hasChanges = true
95101
return fi.mod.WriteAt(b, at)
96102
}
97103

@@ -104,6 +110,7 @@ func (fi *file) GetNode() (*dag.Node, error) {
104110
}
105111

106112
func (fi *file) Truncate(size int64) error {
113+
fi.hasChanges = true
107114
return fi.mod.Truncate(size)
108115
}
109116

0 commit comments

Comments
 (0)