Files
agent-radar 2ed3415fb7
Publish Claude Code Binaries / Stage and publish binaries (push) Canceled after 0s
Publish Tutti App Runtime / Build darwin-arm64 (push) Canceled after 0s
Publish Tutti App Runtime / Build darwin-amd64 (push) Canceled after 0s
Publish Tutti App Runtime / Build linux-amd64 (push) Canceled after 0s
Publish Tutti App Runtime / Build windows-amd64 (push) Canceled after 0s
Sync Tutti Agent Skills / sync (push) Canceled after 0s
Windows Agent Adapters / Test Windows agent adapters (push) Canceled after 0s
Windows Daemon Adapters / Test Windows daemon adapters (push) Canceled after 0s
Publish Tutti App Runtime / Publish runtime catalog (push) Canceled after 0s
源码快照 @ 2026-09-01 (source-only, 剔除非源码素材)
2026-09-01 20:17:27 +08:00

83 lines
2.0 KiB
Go

package workspace
import (
"os"
"path/filepath"
"runtime"
"strings"
workspacefiles "github.com/tutti-os/tutti/packages/workspace/files"
)
var localFilesRuntimeGOOS = runtime.GOOS
var macOSProtectedRootDirectoryNames = map[string]struct{}{
"applications": {},
"bin": {},
"cores": {},
"dev": {},
"etc": {},
"library": {},
"network": {},
"opt": {},
"private": {},
"sbin": {},
"system": {},
"tmp": {},
"usr": {},
"var": {},
"volumes": {},
}
var macOSProtectedHomeDirectoryNames = map[string]struct{}{
"desktop": {},
"documents": {},
"downloads": {},
"movies": {},
"music": {},
"pictures": {},
}
func isMacOSProtectedDirectory(root workspacefiles.WorkspaceRoot, logicalPath workspacefiles.LogicalPath) bool {
if localFilesRuntimeGOOS != "darwin" {
return false
}
physicalPath, err := workspacefiles.JoinPhysicalPath(root, logicalPath)
if err != nil {
return false
}
normalizedPath := cleanPhysicalDirectoryPath(physicalPath)
if isDirectProtectedDirectory(normalizedPath, string(filepath.Separator), macOSProtectedRootDirectoryNames) {
return true
}
homeDir, err := os.UserHomeDir()
if err != nil || strings.TrimSpace(homeDir) == "" {
return false
}
return isDirectProtectedDirectory(
normalizedPath,
cleanPhysicalDirectoryPath(homeDir),
macOSProtectedHomeDirectoryNames,
)
}
func isDirectProtectedDirectory(candidatePath string, parentPath string, protectedNames map[string]struct{}) bool {
candidatePath = cleanPhysicalDirectoryPath(candidatePath)
parentPath = cleanPhysicalDirectoryPath(parentPath)
if candidatePath == parentPath || filepath.Dir(candidatePath) != parentPath {
return false
}
_, protected := protectedNames[strings.ToLower(filepath.Base(candidatePath))]
return protected
}
func cleanPhysicalDirectoryPath(value string) string {
normalized := filepath.Clean(strings.TrimSpace(value))
if normalized == "." || normalized == "" {
return string(filepath.Separator)
}
return normalized
}