forked from TrueCloudLab/rclone
lib/file: reimplement os.OpenFile allowing rename/delete open files under Windows
Normally os.OpenFile under Windows does not allow renaming or deleting open file handles. This package provides equivelents for os.OpenFile, os.Open and os.Create which do allow that.
This commit is contained in:
parent
571b4c060b
commit
42d997f639
4 changed files with 257 additions and 0 deletions
22
lib/file/file.go
Normal file
22
lib/file/file.go
Normal file
|
@ -0,0 +1,22 @@
|
|||
// Package file provides a version of os.OpenFile, the handles of
|
||||
// which can be renamed and deleted under Windows.
|
||||
package file
|
||||
|
||||
import "os"
|
||||
|
||||
// Open opens the named file for reading. If successful, methods on
|
||||
// the returned file can be used for reading; the associated file
|
||||
// descriptor has mode O_RDONLY.
|
||||
// If there is an error, it will be of type *PathError.
|
||||
func Open(name string) (*os.File, error) {
|
||||
return OpenFile(name, os.O_RDONLY, 0)
|
||||
}
|
||||
|
||||
// Create creates the named file with mode 0666 (before umask), truncating
|
||||
// it if it already exists. If successful, methods on the returned
|
||||
// File can be used for I/O; the associated file descriptor has mode
|
||||
// O_RDWR.
|
||||
// If there is an error, it will be of type *PathError.
|
||||
func Create(name string) (*os.File, error) {
|
||||
return OpenFile(name, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0666)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue