feat: split XDG data/state dirs and add Windows legacy migration

Separate backups/trash into XDG_DATA_HOME and logs into XDG_STATE_HOME
instead of keeping everything under XDG_CONFIG_HOME. Add automatic
migration at startup to move existing data to the new locations.

Fix Windows path resolution: DataDir() and StateDir() now fall back to
%AppData% on Windows (matching BaseDir()), preventing incorrect use of
~/.local/share and ~/.local/state paths.

Add MigrateWindowsLegacyDir() to move pre-v0.13.0 data from
~\.config\skillshare\ to %AppData%\skillshare\ on Windows.

Update doctor, oplog, backup, trash, and all tests/docs accordingly.
This commit is contained in:
Willie
2026-02-16 10:41:14 +08:00
parent 41e822d979
commit 0bf84493cc
31 changed files with 469 additions and 99 deletions
+7 -6
View File
@@ -12,6 +12,7 @@ import (
"strings"
"time"
"skillshare/internal/backup"
"skillshare/internal/config"
"skillshare/internal/sync"
"skillshare/internal/trash"
@@ -76,7 +77,9 @@ func cmdDoctorGlobal() error {
return nil
}
ui.Success("Config: %s", config.ConfigPath())
ui.Info("Base directory: %s", config.BaseDir())
ui.Info("Config directory: %s", config.BaseDir())
ui.Info("Data directory: %s", config.DataDir())
ui.Info("State directory: %s", config.StateDir())
cfg, err := config.Load()
if err != nil {
@@ -85,7 +88,7 @@ func cmdDoctorGlobal() error {
}
runDoctorChecks(cfg, result, false)
checkBackupStatus(false, config.ConfigPath())
checkBackupStatus(false, backup.BackupDir())
checkTrashStatus(trash.TrashDir())
checkVersionDoctor(cfg)
checkForUpdates()
@@ -119,7 +122,7 @@ func cmdDoctorProject(root string) error {
}
runDoctorChecks(cfg, result, true)
checkBackupStatus(true, cfgPath)
checkBackupStatus(true, "")
checkTrashStatus(trash.ProjectTrashDir(root))
checkVersionDoctor(cfg)
checkForUpdates()
@@ -569,13 +572,11 @@ func checkDuplicateSkills(cfg *config.Config, result *doctorResult) {
}
// checkBackupStatus shows last backup time
func checkBackupStatus(isProject bool, cfgPath string) {
func checkBackupStatus(isProject bool, backupDir string) {
if isProject {
ui.Info("Backups: not used in project mode")
return
}
backupDir := filepath.Join(filepath.Dir(cfgPath), "backups")
entries, err := os.ReadDir(backupDir)
if err != nil || len(entries) == 0 {
ui.Info("Backups: none found")
+7
View File
@@ -6,6 +6,7 @@ import (
"path/filepath"
"runtime"
"skillshare/internal/config"
"skillshare/internal/ui"
versioncheck "skillshare/internal/version"
)
@@ -44,6 +45,12 @@ func main() {
// Clean up any leftover .old files from Windows self-upgrade
cleanupOldBinary()
// Migrate Windows legacy ~/.config/skillshare → %AppData%\skillshare
config.MigrateWindowsLegacyDir()
// Migrate legacy dirs (backups/trash/logs) to XDG data/state dirs
config.MigrateXDGDirs()
// Set version for other packages to use
versioncheck.Version = version