mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Merge pull request #3177 from Flow-Launcher/symlink
resolve link before using File.Replace
This commit is contained in:
commit
3573580e6f
1 changed files with 10 additions and 12 deletions
|
|
@ -31,11 +31,12 @@ namespace Flow.Launcher.Infrastructure.Storage
|
|||
protected JsonStorage()
|
||||
{
|
||||
}
|
||||
|
||||
public JsonStorage(string filePath)
|
||||
{
|
||||
FilePath = filePath;
|
||||
DirectoryPath = Path.GetDirectoryName(filePath) ?? throw new ArgumentException("Invalid file path");
|
||||
|
||||
|
||||
Helper.ValidateDirectory(DirectoryPath);
|
||||
}
|
||||
|
||||
|
|
@ -97,6 +98,7 @@ namespace Flow.Launcher.Infrastructure.Storage
|
|||
return default;
|
||||
}
|
||||
}
|
||||
|
||||
private void RestoreBackup()
|
||||
{
|
||||
Log.Info($"|JsonStorage.Load|Failed to load settings.json, {BackupFilePath} restored successfully");
|
||||
|
|
@ -179,25 +181,21 @@ namespace Flow.Launcher.Infrastructure.Storage
|
|||
public void Save()
|
||||
{
|
||||
string serialized = JsonSerializer.Serialize(Data,
|
||||
new JsonSerializerOptions
|
||||
{
|
||||
WriteIndented = true
|
||||
});
|
||||
new JsonSerializerOptions { WriteIndented = true });
|
||||
|
||||
File.WriteAllText(TempFilePath, serialized);
|
||||
|
||||
AtomicWriteSetting();
|
||||
}
|
||||
|
||||
public async Task SaveAsync()
|
||||
{
|
||||
var tempOutput = File.OpenWrite(TempFilePath);
|
||||
await using var tempOutput = File.OpenWrite(TempFilePath);
|
||||
await JsonSerializer.SerializeAsync(tempOutput, Data,
|
||||
new JsonSerializerOptions
|
||||
{
|
||||
WriteIndented = true
|
||||
});
|
||||
new JsonSerializerOptions { WriteIndented = true });
|
||||
AtomicWriteSetting();
|
||||
}
|
||||
|
||||
private void AtomicWriteSetting()
|
||||
{
|
||||
if (!File.Exists(FilePath))
|
||||
|
|
@ -206,9 +204,9 @@ namespace Flow.Launcher.Infrastructure.Storage
|
|||
}
|
||||
else
|
||||
{
|
||||
File.Replace(TempFilePath, FilePath, BackupFilePath);
|
||||
var finalFilePath = new FileInfo(FilePath).LinkTarget ?? FilePath;
|
||||
File.Replace(TempFilePath, finalFilePath, BackupFilePath);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue