59
added to MFS. Any content can be lazily referenced from MFS with the command
60
"ipfs files cp /ipfs/<cid> /some/path/" (see ipfs files cp --help).
61
62
-
63
-NOTE:
64
-Most of the subcommands of 'ipfs files' accept the '--flush' flag. It defaults
65
-to true. Use caution when setting this flag to false. It will improve
62
+NOTE: Most of the subcommands of 'ipfs files' accept the '--flush' flag. It
63
+defaults to true and ensures two things: 1) that the changes are reflected in
64
+the full MFS structure (updated CIDs) 2) that the parent-folder's cache is
65
+cleared. Use caution when setting this flag to false. It will improve
66
performance for large numbers of file operations, but it does so at the cost
67
-of consistency guarantees. If the daemon is unexpectedly killed before running
68
-'ipfs files flush' on the files in question, then data may be lost. This also
69
-applies to run 'ipfs repo gc' concurrently with '--flush=false'
70
-operations.
71
-`,
67
+of consistency guarantees and unbound growth of the directories' in-memory
68
+caches. If the daemon is unexpectedly killed before running 'ipfs files
69
+flush' on the files in question, then data may be lost. This also applies to
70
+run 'ipfs repo gc' concurrently with '--flush=false' operations. We recommend
71
+flushing paths reguarly with 'ipfs files flush', specially the folders on
72
+which many write operations are happening, as a way to clear the directory
73
+cache, free memory and speed up read operations.`,
74
},
75
Options: []cmds.Option{
76
cmds.BoolOption(filesFlushOptionName, "f", "Flush target and ancestors after write.").WithDefault(true),
493
}
494
495
if flush {
494
- _, err := mfs.FlushPath(req.Context, nd.FilesRoot, dst)
495
- if err != nil {
496
+ if _, err := mfs.FlushPath(req.Context, nd.FilesRoot, dst); err != nil {
497
return fmt.Errorf("cp: cannot flush the created file %s: %s", dst, err)
498
}
499
+ // Flush parent to clear directory cache and free memory.
500
+ parent := gopath.Dir(dst)
501
+ if _, err = mfs.FlushPath(req.Context, nd.FilesRoot, parent); err != nil {
502
+ return fmt.Errorf("cp: cannot flush the created file's parent folder %s: %s", dst, err)
503
+ }
504
}
505
506
return nil
798
}
799
800
err = mfs.Mv(nd.FilesRoot, src, dst)
795
- if err == nil && flush {
796
- _, err = mfs.FlushPath(req.Context, nd.FilesRoot, "/")
801
+ if err != nil {
802
+ return err
803
}
798
- return err
804
+ if flush {
805
+ parentSrc := gopath.Dir(src)
806
+ parentDst := gopath.Dir(dst)
807
+ // Flush parent to clear directory cache and free memory.
808
+ if _, err = mfs.FlushPath(req.Context, nd.FilesRoot, parentDst); err != nil {
809
+ return fmt.Errorf("cp: cannot flush the destination file's parent folder %s: %s", dst, err)
810
+ }
811
+
812
+ // Avoid re-flushing when moving within the same folder.
813
+ if parentSrc != parentDst {
814
+ if _, err = mfs.FlushPath(req.Context, nd.FilesRoot, parentSrc); err != nil {
815
+ return fmt.Errorf("cp: cannot flush the source's file's parent folder %s: %s", dst, err)
816
+ }
817
+ }
818
+
819
+ if _, err = mfs.FlushPath(req.Context, nd.FilesRoot, "/"); err != nil {
820
+ return err
821
+ }
822
+ }
823
+
824
+ return nil
825
},
826
}
827
969
flog.Error("files: error closing file mfs file descriptor", err)
970
}
971
}
972
+ if flush {
973
+ // Flush parent to clear directory cache and free memory.
974
+ parent := gopath.Dir(path)
975
+ if _, err := mfs.FlushPath(req.Context, nd.FilesRoot, parent); err != nil {
976
+ if retErr == nil {
977
+ retErr = err
978
+ } else {
979
+ flog.Error("files: flushing the parent folder", err)
980
+ }
981
+ }
982
+ }
983
}()
984
985
if trunc {
1142
return err
1143
}
1144
1108
- err = updatePath(nd.FilesRoot, path, prefix)
1109
- if err == nil && flush {
1110
- _, err = mfs.FlushPath(req.Context, nd.FilesRoot, path)
1145
+ if err := updatePath(nd.FilesRoot, path, prefix); err != nil {
1146
+ return err
1147
}
1112
- return err
1148
+ if flush {
1149
+ if _, err = mfs.FlushPath(req.Context, nd.FilesRoot, path); err != nil {
1150
+ return err
1151
+ }
1152
+ // Flush parent to clear directory cache and free memory.
1153
+ parent := gopath.Dir(path)
1154
+ if _, err = mfs.FlushPath(req.Context, nd.FilesRoot, parent); err != nil {
1155
+ return err
1156
+ }
1157
+ }
1158
+ return nil
1159
},
1160
}
1161