files: update for MFS changes
1. Update to use the new `Open` function. 2. Use `Flush()` instead of `Sync()` as sync was removed as useless (this should have been calling `Flush()` all along). License: MIT Signed-off-by: Steven Allen <steven@stebalien.com>
Steven Allen committed
Jan 8, 2019 at 19:45 UTC
489786a53f17b772b73143a01130b32416093379
2 files changed
+18
-32
core/commands/files.go
+2
-2
@@ -551,7 +551,7 @@ Examples:
551
return fmt.Errorf("%s was not a file", path)
552
}
553
554
- rfd, err := fi.Open(mfs.OpenReadOnly, false)
554
+ rfd, err := fi.Open(mfs.Flags{Read: true})
555
if err != nil {
556
return err
557
}
@@ -736,7 +736,7 @@ stat' on the file or any of its ancestors.
736
fi.RawLeaves = rawLeaves
737
}
738
739
- wfd, err := fi.Open(mfs.OpenWriteOnly, flush)
739
+ wfd, err := fi.Open(mfs.Flags{Write: true, Sync: flush})
740
if err != nil {
741
return err
742
}
fuse/ipns/ipns_unix.go
+16
-30
@@ -402,12 +402,13 @@ func (fi *File) Setattr(ctx context.Context, req *fuse.SetattrRequest, resp *fus
402
return nil
403
}
404
405
-// Fsync flushes the content in the file to disk, but does not
406
-// update the dag tree internally
405
+// Fsync flushes the content in the file to disk.
406
func (fi *FileNode) Fsync(ctx context.Context, req *fuse.FsyncRequest) error {
407
+ // This needs to perform a *full* flush because, in MFS, a write isn't
408
+ // persisted until the root is updated.
409
errs := make(chan error, 1)
410
go func() {
410
- errs <- fi.fi.Sync()
411
+ errs <- fi.fi.Flush()
412
}()
413
select {
414
case err := <-errs:
@@ -418,7 +419,8 @@ func (fi *FileNode) Fsync(ctx context.Context, req *fuse.FsyncRequest) error {
419
}
420
421
func (fi *File) Forget() {
421
- err := fi.fi.Sync()
422
+ // TODO(steb): this seems like a place where we should be *uncaching*, not flushing.
423
+ err := fi.fi.Flush()
424
if err != nil {
425
log.Debug("forget file error: ", err)
426
}
@@ -434,19 +436,11 @@ func (dir *Directory) Mkdir(ctx context.Context, req *fuse.MkdirRequest) (fs.Nod
436
}
437
438
func (fi *FileNode) Open(ctx context.Context, req *fuse.OpenRequest, resp *fuse.OpenResponse) (fs.Handle, error) {
437
- var mfsflag int
438
- switch {
439
- case req.Flags.IsReadOnly():
440
- mfsflag = mfs.OpenReadOnly
441
- case req.Flags.IsWriteOnly():
442
- mfsflag = mfs.OpenWriteOnly
443
- case req.Flags.IsReadWrite():
444
- mfsflag = mfs.OpenReadWrite
445
- default:
446
- return nil, errors.New("unsupported flag type")
447
- }
448
-
449
- fd, err := fi.fi.Open(mfsflag, true)
439
+ fd, err := fi.fi.Open(mfs.Flags{
440
+ Read: req.Flags.IsReadOnly() || req.Flags.IsReadWrite(),
441
+ Write: req.Flags.IsWriteOnly() || req.Flags.IsReadWrite(),
442
+ Sync: true,
443
+ })
444
if err != nil {
445
return nil, err
446
}
@@ -502,19 +496,11 @@ func (dir *Directory) Create(ctx context.Context, req *fuse.CreateRequest, resp
496
497
nodechild := &FileNode{fi: fi}
498
505
- var openflag int
506
- switch {
507
- case req.Flags.IsReadOnly():
508
- openflag = mfs.OpenReadOnly
509
- case req.Flags.IsWriteOnly():
510
- openflag = mfs.OpenWriteOnly
511
- case req.Flags.IsReadWrite():
512
- openflag = mfs.OpenReadWrite
513
- default:
514
- return nil, nil, errors.New("unsupported open mode")
515
- }
516
-
517
- fd, err := fi.Open(openflag, true)
499
+ fd, err := fi.Open(mfs.Flags{
500
+ Read: req.Flags.IsReadOnly() || req.Flags.IsReadWrite(),
501
+ Write: req.Flags.IsWriteOnly() || req.Flags.IsReadWrite(),
502
+ Sync: true,
503
+ })
504
if err != nil {
505
return nil, nil, err
506
}