]> Cypherpunks.ru repositories - nncp.git/blobdiff - src/tmp.go
Raise copyright years
[nncp.git] / src / tmp.go
index 6d1e49c08e132794b5faa1934342bbb7b5d32823..aee58677518a562c55d7be7c56931061b2dbf83c 100644 (file)
@@ -1,6 +1,6 @@
 /*
 NNCP -- Node to Node copy, utilities for store-and-forward data exchange
-Copyright (C) 2016-2021 Sergey Matveev <stargrave@stargrave.org>
+Copyright (C) 2016-2022 Sergey Matveev <stargrave@stargrave.org>
 
 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
@@ -37,13 +37,8 @@ func TempFile(dir, prefix string) (*os.File, error) {
 
 func (ctx *Ctx) NewTmpFile() (*os.File, error) {
        jobsPath := filepath.Join(ctx.Spool, "tmp")
-       if _, err := os.Stat(jobsPath); err != nil {
-               if !os.IsNotExist(err) {
-                       return nil, err
-               }
-               if err := os.MkdirAll(jobsPath, os.FileMode(0777)); err != nil {
-                       return nil, err
-               }
+       if err := ensureDir(jobsPath); err != nil {
+               return nil, err
        }
        fd, err := TempFile(jobsPath, "")
        if err == nil {
@@ -100,13 +95,8 @@ func (tmp *TmpFileWHash) Checksum() string {
 
 func (tmp *TmpFileWHash) Commit(dir string) error {
        var err error
-       if _, err = os.Stat(dir); err != nil {
-               if !os.IsNotExist(err) {
-                       return err
-               }
-               if err = os.MkdirAll(dir, os.FileMode(0777)); err != nil {
-                       return err
-               }
+       if err = ensureDir(dir); err != nil {
+               return err
        }
        if err = tmp.W.Flush(); err != nil {
                tmp.Fd.Close()