eclipse/lib/gitcache/unixutil.go

47 lines
907 B
Go

// Copyright (C) 2024 Umorpha Systems
// SPDX-License-Identifier: AGPL-3.0-or-later
package gitcache
import (
"errors"
"os"
"time"
)
func touch(filename string) error {
fh, err := os.OpenFile(filename, os.O_CREATE|os.O_WRONLY, 0o666)
if err != nil {
return err
}
return fh.Close()
}
func mtime(filename string) (time.Time, error) {
fi, err := os.Stat(filename)
if err != nil {
return time.Time{}, err
}
return fi.ModTime(), nil
}
func mkdirAllowExisting(dirname string) error {
// Fast-path - we expect to call this with existing dirs far
// more often than with non-existing dirs.
if fi, err := os.Stat(dirname); err == nil && fi.IsDir() {
return nil
}
if err := os.Mkdir(dirname, 0o777); err != nil {
// Check for a race.
if errors.Is(err, os.ErrExist) {
if fi, err := os.Stat(dirname); err == nil && fi.IsDir() {
return nil
}
}
return err
}
return nil
}