mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-06 03:20:13 +08:00
feat: put cmd-hook in container feat: cmd-hook request type, auto restart setup feat: handle ls
40 lines
599 B
Go
40 lines
599 B
Go
package main
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
)
|
|
|
|
type FileType string
|
|
|
|
const (
|
|
FileTypeFile FileType = "file"
|
|
FileTypeDir FileType = "directory"
|
|
)
|
|
|
|
func resolvePath(path string) string {
|
|
if filepath.IsAbs(path) {
|
|
return path
|
|
}
|
|
return filepath.Join(os.Getenv("PWD"), path)
|
|
}
|
|
|
|
func fileExists(path string) (FileType, error) {
|
|
fileInfo, err := os.Stat(path)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
if fileInfo.IsDir() {
|
|
return FileTypeDir, nil
|
|
}
|
|
return FileTypeFile, nil
|
|
}
|
|
|
|
func isDir(path string) bool {
|
|
info, err := os.Stat(path)
|
|
if err != nil {
|
|
return false
|
|
}
|
|
return info.IsDir()
|
|
}
|