refactor: stores runtime data in ~/.sourcegit instead of ~/.local/share/SourceGit (#2088)

Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
leo
2026-02-03 11:02:29 +08:00
parent 8a5b0245b6
commit 65d122f9ce
2 changed files with 18 additions and 27 deletions

View File

@@ -72,11 +72,11 @@ You can download the latest stable from [Releases](https://github.com/sourcegit-
This software creates a folder, which is platform-dependent, to store user settings, downloaded avatars and crash logs.
| OS | PATH |
|---------|-------------------------------------------------|
| Windows | `%APPDATA%\SourceGit` |
| Linux | `${HOME}/.local/share/SourceGit` |
| macOS | `${HOME}/Library/Application Support/SourceGit` |
| OS | PATH |
|---------|-------------------------------------------|
| Windows | `%APPDATA%\SourceGit` |
| Linux | `~/.sourcegit` |
| macOS | `~/Library/Application Support/SourceGit` |
> [!TIP]
> * You can open this data storage directory from the main menu `Open Data Storage Directory`.

View File

@@ -44,32 +44,23 @@ namespace SourceGit.Native
return portableDir;
}
// Gets the `$XDG_DATA_HOME` dir.
// Runtime data dir: ~/.sourcegit
var home = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
var dataHome = Path.Combine(home, ".local", "share");
if (!Directory.Exists(dataHome))
Directory.CreateDirectory(dataHome);
var dataDir = Path.Combine(home, ".sourcegit");
if (Directory.Exists(dataDir))
return dataDir;
// Gets the data dir and migrate old data.
var dataDir = Path.Combine(dataHome, "SourceGit");
if (!Directory.Exists(dataDir))
// Migrate old data: ~/.config/SourceGit
var oldDataDir = Path.Combine(home, ".config", "SourceGit");
if (Directory.Exists(oldDataDir))
{
var oldDataDir = Path.Combine(home, ".config", "SourceGit"); // Old data dir: $XDG_CONFIG_HOME/SourceGit
var oldFallbackDir = Path.Combine(home, ".sourcegit"); // Old fallback folder: $HOME/.sourcegit
var moveDir = Directory.Exists(oldDataDir)
? oldDataDir
: (Directory.Exists(oldFallbackDir) ? oldFallbackDir : string.Empty);
if (!string.IsNullOrEmpty(moveDir))
try
{
try
{
Directory.Move(moveDir, dataDir);
}
catch
{
// Ignore errors
}
Directory.Move(oldDataDir, dataDir);
}
catch
{
// Ignore errors
}
}