Files
linux-odyssey/services/cmd-hook/utils.go
T
Justin Lin 0b08a9a5d9 feat: init cmd-hook and move terminal-service to services directory
feat: put cmd-hook in container

feat: cmd-hook request type, auto restart setup

feat: handle ls
2025-05-05 19:51:06 +08:00

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()
}