Skip to content

Commit

Permalink
feat: add OpenOverride method to Path struct
Browse files Browse the repository at this point in the history
  • Loading branch information
sidneycao committed Jun 26, 2024
1 parent 961a756 commit 6c74926
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions file.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,21 @@ func (p *Path) Open() error {
return nil
}

func (p *Path) OpenOverride() error {
if p.IsDir {
return errors.New("this object is dir, can not be opened")
}

f, err := os.OpenFile(p.AbsPath, os.O_RDWR|os.O_TRUNC|os.O_CREATE, 0644)
if err != nil {
return err
}

p.File = f
p.refresh(p.AbsPath)
return nil
}

// Close a file.
func (p *Path) Close() error {
if p.File != nil {
Expand Down

0 comments on commit 6c74926

Please sign in to comment.