X-Git-Url: http://www.git.cypherpunks.ru/?a=blobdiff_plain;f=src%2Ftmp.go;h=4a43eaa41a2675969f0d7109fe362f5304c93866;hb=7696544068749db54f07c21cd658557905302fe4;hp=7b9ded1b6220450a61aa0d2b301caf7b11842ce9;hpb=54b0f8a0e20847d666dd445bd92c282fd9ab5dec;p=nncp.git diff --git a/src/tmp.go b/src/tmp.go index 7b9ded1..4a43eaa 100644 --- a/src/tmp.go +++ b/src/tmp.go @@ -1,6 +1,6 @@ /* NNCP -- Node to Node copy, utilities for store-and-forward data exchange -Copyright (C) 2016-2021 Sergey Matveev +Copyright (C) 2016-2022 Sergey Matveev This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -28,6 +28,12 @@ import ( "time" ) +var NoSync bool + +func init() { + NoSync = os.Getenv(CfgNoSync) != "" +} + func TempFile(dir, prefix string) (*os.File, error) { // Assume that probability of suffix collision is negligible suffix := strconv.FormatInt(time.Now().UnixNano()+int64(os.Getpid()), 16) @@ -37,7 +43,7 @@ func TempFile(dir, prefix string) (*os.File, error) { func (ctx *Ctx) NewTmpFile() (*os.File, error) { jobsPath := filepath.Join(ctx.Spool, "tmp") - if err := os.MkdirAll(jobsPath, os.FileMode(0777)); err != nil { + if err := ensureDir(jobsPath); err != nil { return nil, err } fd, err := TempFile(jobsPath, "") @@ -77,6 +83,9 @@ func (tmp *TmpFileWHash) Cancel() { } func DirSync(dirPath string) error { + if NoSync { + return nil + } fd, err := os.Open(dirPath) if err != nil { return err @@ -95,16 +104,18 @@ func (tmp *TmpFileWHash) Checksum() string { func (tmp *TmpFileWHash) Commit(dir string) error { var err error - if err = os.MkdirAll(dir, os.FileMode(0777)); err != nil { + if err = ensureDir(dir); err != nil { return err } if err = tmp.W.Flush(); err != nil { tmp.Fd.Close() return err } - if err = tmp.Fd.Sync(); err != nil { - tmp.Fd.Close() - return err + if !NoSync { + if err = tmp.Fd.Sync(); err != nil { + tmp.Fd.Close() + return err + } } if err = tmp.Fd.Close(); err != nil { return err