mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-18 18:04:17 +00:00
Finder writes .DS_Store into any folder it opens, and Explorer writes Thumbs.db and desktop.ini. These counted as skill content, so opening an installed skill in a file manager made check report it as modified, hid update_available, and made update skip it unless run with --force, which also lowers the audit threshold. Skip them when hashing a skill, drop hashes earlier versions recorded for them (from .metadata.json and from legacy sidecar migration), and keep audit integrity from reporting them. Their content is still audited. Closes #743
75 lines
2.5 KiB
Go
75 lines
2.5 KiB
Go
package utils
|
|
|
|
import "strings"
|
|
|
|
// NestedSeparator is the separator used in flat names for nested paths.
|
|
// Example: "_team/frontend/ui" becomes "_team__frontend__ui"
|
|
const NestedSeparator = "__"
|
|
|
|
// TrackedRepoPrefix marks directories as tracked repositories.
|
|
// Directories starting with _ are cloned repos that preserve .git
|
|
const TrackedRepoPrefix = "_"
|
|
|
|
// IsHidden checks if a file/directory name starts with a dot.
|
|
// Returns false for empty strings to prevent panic on empty names.
|
|
func IsHidden(name string) bool {
|
|
return len(name) > 0 && name[0] == '.'
|
|
}
|
|
|
|
// IsOSMetadataFile reports whether name is a file the OS file manager writes
|
|
// into folders on its own: Finder's .DS_Store, Explorer's Thumbs.db and
|
|
// desktop.ini. Windows names are case-insensitive, so all are compared that way.
|
|
func IsOSMetadataFile(name string) bool {
|
|
switch strings.ToLower(name) {
|
|
case ".ds_store", "thumbs.db", "desktop.ini":
|
|
return true
|
|
}
|
|
return false
|
|
}
|
|
|
|
// HasTildePrefix checks if a path starts with ~.
|
|
// Returns false for empty strings to prevent panic on empty paths.
|
|
func HasTildePrefix(path string) bool {
|
|
return len(path) > 0 && path[0] == '~'
|
|
}
|
|
|
|
// PathToFlatName converts a relative path to a flat name using __ as separator.
|
|
// Example: "_team/frontend/ui" -> "_team__frontend__ui"
|
|
// Example: "my-skill" -> "my-skill" (no change for flat paths)
|
|
func PathToFlatName(relPath string) string {
|
|
// Normalize path separators and remove leading/trailing slashes
|
|
relPath = strings.ReplaceAll(relPath, "\\", "/")
|
|
relPath = strings.Trim(relPath, "/")
|
|
|
|
if relPath == "" || relPath == "." {
|
|
return ""
|
|
}
|
|
|
|
// Replace / with __
|
|
return strings.ReplaceAll(relPath, "/", NestedSeparator)
|
|
}
|
|
|
|
// FlatNameToPath converts a flat name back to a relative path.
|
|
// Example: "_team__frontend__ui" -> "_team/frontend/ui"
|
|
// Example: "my-skill" -> "my-skill" (no change for flat names)
|
|
func FlatNameToPath(flatName string) string {
|
|
if flatName == "" {
|
|
return ""
|
|
}
|
|
|
|
// Replace __ with /
|
|
return strings.ReplaceAll(flatName, NestedSeparator, "/")
|
|
}
|
|
|
|
// IsTrackedRepoDir checks if a directory name indicates a tracked repository.
|
|
// Tracked repos start with _ and contain .git directory.
|
|
func IsTrackedRepoDir(name string) bool {
|
|
return strings.HasPrefix(name, TrackedRepoPrefix)
|
|
}
|
|
|
|
// HasNestedSeparator checks if a name contains the nested separator (__).
|
|
// This indicates the name came from a nested path structure.
|
|
func HasNestedSeparator(name string) bool {
|
|
return strings.Contains(name, NestedSeparator)
|
|
}
|