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()
|
protected JsonStorage()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public JsonStorage(string filePath)
|
public JsonStorage(string filePath)
|
||||||
{
|
{
|
||||||
FilePath = filePath;
|
FilePath = filePath;
|
||||||
DirectoryPath = Path.GetDirectoryName(filePath) ?? throw new ArgumentException("Invalid file path");
|
DirectoryPath = Path.GetDirectoryName(filePath) ?? throw new ArgumentException("Invalid file path");
|
||||||
|
|
||||||
Helper.ValidateDirectory(DirectoryPath);
|
Helper.ValidateDirectory(DirectoryPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -97,6 +98,7 @@ namespace Flow.Launcher.Infrastructure.Storage
|
||||||
return default;
|
return default;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void RestoreBackup()
|
private void RestoreBackup()
|
||||||
{
|
{
|
||||||
Log.Info($"|JsonStorage.Load|Failed to load settings.json, {BackupFilePath} restored successfully");
|
Log.Info($"|JsonStorage.Load|Failed to load settings.json, {BackupFilePath} restored successfully");
|
||||||
|
|
@ -179,25 +181,21 @@ namespace Flow.Launcher.Infrastructure.Storage
|
||||||
public void Save()
|
public void Save()
|
||||||
{
|
{
|
||||||
string serialized = JsonSerializer.Serialize(Data,
|
string serialized = JsonSerializer.Serialize(Data,
|
||||||
new JsonSerializerOptions
|
new JsonSerializerOptions { WriteIndented = true });
|
||||||
{
|
|
||||||
WriteIndented = true
|
|
||||||
});
|
|
||||||
|
|
||||||
File.WriteAllText(TempFilePath, serialized);
|
File.WriteAllText(TempFilePath, serialized);
|
||||||
|
|
||||||
AtomicWriteSetting();
|
AtomicWriteSetting();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task SaveAsync()
|
public async Task SaveAsync()
|
||||||
{
|
{
|
||||||
var tempOutput = File.OpenWrite(TempFilePath);
|
await using var tempOutput = File.OpenWrite(TempFilePath);
|
||||||
await JsonSerializer.SerializeAsync(tempOutput, Data,
|
await JsonSerializer.SerializeAsync(tempOutput, Data,
|
||||||
new JsonSerializerOptions
|
new JsonSerializerOptions { WriteIndented = true });
|
||||||
{
|
|
||||||
WriteIndented = true
|
|
||||||
});
|
|
||||||
AtomicWriteSetting();
|
AtomicWriteSetting();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void AtomicWriteSetting()
|
private void AtomicWriteSetting()
|
||||||
{
|
{
|
||||||
if (!File.Exists(FilePath))
|
if (!File.Exists(FilePath))
|
||||||
|
|
@ -206,9 +204,9 @@ namespace Flow.Launcher.Infrastructure.Storage
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
File.Replace(TempFilePath, FilePath, BackupFilePath);
|
var finalFilePath = new FileInfo(FilePath).LinkTarget ?? FilePath;
|
||||||
|
File.Replace(TempFilePath, finalFilePath, BackupFilePath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue