eclipse/lib/gitcache/unixutil.go

47 lines
907 B
Go
Raw Normal View History

2024-01-11 20:36:03 +00:00
// Copyright (C) 2024 Umorpha Systems
// SPDX-License-Identifier: AGPL-3.0-or-later
package gitcache
import (
2024-01-12 19:50:38 +00:00
"errors"
2024-01-11 20:36:03 +00:00
"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
}
2024-01-12 19:50:38 +00:00
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
}