Skip to content
This repository has been archived by the owner on Jun 26, 2023. It is now read-only.

Commit

Permalink
Add stateCreated as default fd state
Browse files Browse the repository at this point in the history
Added a new state for a freshly opened `fileDescriptor`.
In `flushUp` only bubble up update if state is either `stateDirty` or
`stateCreated`. `stateFlushed` should prevent bubble up.
  • Loading branch information
nmalhotra committed Dec 25, 2018
1 parent 3191540 commit 64e7cdb
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
7 changes: 5 additions & 2 deletions fd.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import (
type state uint8

const (
stateFlushed state = iota
stateCreated state = iota
stateFlushed
stateDirty
stateClosed
)
Expand Down Expand Up @@ -153,7 +154,7 @@ func (fi *fileDescriptor) flushUp(fullSync bool) error {
fi.inode.node = nd
fi.inode.nodeLock.Unlock()
fallthrough
case stateFlushed:
case stateCreated:
if !fullSync {
return nil
}
Expand All @@ -169,6 +170,8 @@ func (fi *fileDescriptor) flushUp(fullSync bool) error {
}
fi.state = stateFlushed
return nil
case stateFlushed:
return nil
default:
panic("invalid state")
}
Expand Down
1 change: 1 addition & 0 deletions file.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ func (fi *File) Open(flags Flags) (_ FileDescriptor, _retErr error) {
inode: fi,
flags: flags,
mod: dmod,
state: stateCreated,
}, nil
}

Expand Down
1 change: 1 addition & 0 deletions root.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ const (
// (Not to be confused with the `unixfs.FSNode`.)
type FSNode interface {
GetNode() (ipld.Node, error)

Flush() error
Type() NodeType
}
Expand Down

0 comments on commit 64e7cdb

Please sign in to comment.