diff options
author | Thomas Voss <mail@thomasvoss.com> | 2025-06-14 00:45:04 +0200 |
---|---|---|
committer | Thomas Voss <mail@thomasvoss.com> | 2025-06-14 00:45:04 +0200 |
commit | fe2bae01c6b14eef0e61cd4a6bd50e814de4bb58 (patch) | |
tree | 60fbda65d5fa3a9afc966bce51b6968e966baf4c /src/watch/watch.go | |
parent | 2d5ca3a6cd507ef29eb13b3a78232264a2817e81 (diff) |
Move some packages to pkg/
Diffstat (limited to 'src/watch/watch.go')
-rw-r--r-- | src/watch/watch.go | 41 |
1 files changed, 0 insertions, 41 deletions
diff --git a/src/watch/watch.go b/src/watch/watch.go deleted file mode 100644 index 84f9ed9..0000000 --- a/src/watch/watch.go +++ /dev/null @@ -1,41 +0,0 @@ -package watch - -import ( - "errors" - "io/fs" - "log" - "os" - "time" - - . "git.thomasvoss.com/euro-cash.eu/src/try" -) - -func File(path string, f func()) { - impl(path, os.Stat, f) -} - -func FileFS(dir fs.FS, path string, f func()) { - impl(path, func(path string) (os.FileInfo, error) { - return fs.Stat(dir, path) - }, f) -} - -func impl(path string, statfn func(string) (os.FileInfo, error), f func()) { - ostat := Try2(statfn(path)) - - for { - nstat, err := statfn(path) - switch { - case errors.Is(err, os.ErrNotExist): - return - case err != nil: - log.Println(err) - } - - if nstat.ModTime() != ostat.ModTime() { - f() - ostat = nstat - } - time.Sleep(1 * time.Second) - } -} |