X-Git-Url: http://www.git.cypherpunks.ru/?a=blobdiff_plain;f=src%2Ftmp.go;h=4a43eaa41a2675969f0d7109fe362f5304c93866;hb=HEAD;hp=aee58677518a562c55d7be7c56931061b2dbf83c;hpb=0367cce2741e1ce6a89a49fd5c4e9df6005c9744;p=nncp.git diff --git a/src/tmp.go b/src/tmp.go index aee5867..c4f57c1 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-2022 Sergey Matveev +Copyright (C) 2016-2023 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) @@ -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 @@ -102,9 +111,11 @@ func (tmp *TmpFileWHash) Commit(dir string) error { 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