]> Cypherpunks.ru repositories - nncp.git/blobdiff - src/tmp.go
.hdr files
[nncp.git] / src / tmp.go
index 0a987722b57e665461a7205c0db7eaf851fd8d11..b99ef3d49a9a4d36bc6d1b39c310d50bf9d01722 100644 (file)
@@ -44,7 +44,7 @@ func (ctx *Ctx) NewTmpFile() (*os.File, error) {
        }
        fd, err := TempFile(jobsPath, "")
        if err == nil {
-               ctx.LogD("tmp", SDS{"src": fd.Name()}, "created")
+               ctx.LogD("tmp", LEs{{"Src", fd.Name()}}, "created")
        }
        return fd, err
 }
@@ -74,8 +74,8 @@ func (ctx *Ctx) NewTmpFileWHash() (*TmpFileWHash, error) {
 }
 
 func (tmp *TmpFileWHash) Cancel() {
-       tmp.Fd.Truncate(0) // #nosec G104
-       tmp.Fd.Close() // #nosec G104
+       tmp.Fd.Truncate(0)       // #nosec G104
+       tmp.Fd.Close()           // #nosec G104
        os.Remove(tmp.Fd.Name()) // #nosec G104
 }
 
@@ -92,6 +92,10 @@ func DirSync(dirPath string) error {
        return fd.Close()
 }
 
+func (tmp *TmpFileWHash) Checksum() string {
+       return Base32Codec.EncodeToString(tmp.Hsh.Sum(nil))
+}
+
 func (tmp *TmpFileWHash) Commit(dir string) error {
        var err error
        if err = os.MkdirAll(dir, os.FileMode(0777)); err != nil {
@@ -108,8 +112,8 @@ func (tmp *TmpFileWHash) Commit(dir string) error {
        if err = tmp.Fd.Close(); err != nil {
                return err
        }
-       checksum := Base32Codec.EncodeToString(tmp.Hsh.Sum(nil))
-       tmp.ctx.LogD("tmp", SDS{"src": tmp.Fd.Name(), "dst": checksum}, "commit")
+       checksum := tmp.Checksum()
+       tmp.ctx.LogD("tmp", LEs{{"Src", tmp.Fd.Name()}, {"Dst", checksum}}, "commit")
        if err = os.Rename(tmp.Fd.Name(), filepath.Join(dir, checksum)); err != nil {
                return err
        }