2015-08-16 10:39:38 +00:00
|
|
|
// +build !windows
|
|
|
|
|
|
|
|
package local
|
|
|
|
|
|
|
|
import (
|
2021-07-09 15:11:39 +00:00
|
|
|
"errors"
|
2015-08-16 10:39:38 +00:00
|
|
|
"os"
|
2021-07-09 15:11:39 +00:00
|
|
|
"syscall"
|
2017-07-23 12:21:03 +00:00
|
|
|
|
|
|
|
"github.com/restic/restic/internal/fs"
|
2015-08-16 10:39:38 +00:00
|
|
|
)
|
|
|
|
|
2021-07-09 15:11:39 +00:00
|
|
|
// fsyncDir flushes changes to the directory dir.
|
|
|
|
func fsyncDir(dir string) error {
|
|
|
|
d, err := os.Open(dir)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
err = d.Sync()
|
|
|
|
if errors.Is(err, syscall.ENOTSUP) {
|
|
|
|
err = nil
|
|
|
|
}
|
|
|
|
|
|
|
|
cerr := d.Close()
|
|
|
|
if err == nil {
|
|
|
|
err = cerr
|
|
|
|
}
|
|
|
|
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2015-08-16 10:39:38 +00:00
|
|
|
// set file to readonly
|
2020-10-06 16:46:19 +00:00
|
|
|
func setFileReadonly(f string, mode os.FileMode) error {
|
|
|
|
return fs.Chmod(f, mode&^0222)
|
2015-08-16 10:39:38 +00:00
|
|
|
}
|