Skip to content

Commit 3573580

Browse files
Merge pull request #3177 from Flow-Launcher/symlink
resolve link before using File.Replace
2 parents 2bc9203 + 4b38e0e commit 3573580

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

Flow.Launcher.Infrastructure/Storage/JsonStorage.cs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,12 @@ namespace Flow.Launcher.Infrastructure.Storage
3131
protected JsonStorage()
3232
{
3333
}
34+
3435
public JsonStorage(string filePath)
3536
{
3637
FilePath = filePath;
3738
DirectoryPath = Path.GetDirectoryName(filePath) ?? throw new ArgumentException("Invalid file path");
38-
39+
3940
Helper.ValidateDirectory(DirectoryPath);
4041
}
4142

@@ -97,6 +98,7 @@ private async ValueTask<T> LoadBackupOrDefaultAsync()
9798
return default;
9899
}
99100
}
101+
100102
private void RestoreBackup()
101103
{
102104
Log.Info($"|JsonStorage.Load|Failed to load settings.json, {BackupFilePath} restored successfully");
@@ -179,25 +181,21 @@ private void BackupOriginFile()
179181
public void Save()
180182
{
181183
string serialized = JsonSerializer.Serialize(Data,
182-
new JsonSerializerOptions
183-
{
184-
WriteIndented = true
185-
});
184+
new JsonSerializerOptions { WriteIndented = true });
186185

187186
File.WriteAllText(TempFilePath, serialized);
188187

189188
AtomicWriteSetting();
190189
}
190+
191191
public async Task SaveAsync()
192192
{
193-
var tempOutput = File.OpenWrite(TempFilePath);
193+
await using var tempOutput = File.OpenWrite(TempFilePath);
194194
await JsonSerializer.SerializeAsync(tempOutput, Data,
195-
new JsonSerializerOptions
196-
{
197-
WriteIndented = true
198-
});
195+
new JsonSerializerOptions { WriteIndented = true });
199196
AtomicWriteSetting();
200197
}
198+
201199
private void AtomicWriteSetting()
202200
{
203201
if (!File.Exists(FilePath))
@@ -206,9 +204,9 @@ private void AtomicWriteSetting()
206204
}
207205
else
208206
{
209-
File.Replace(TempFilePath, FilePath, BackupFilePath);
207+
var finalFilePath = new FileInfo(FilePath).LinkTarget ?? FilePath;
208+
File.Replace(TempFilePath, finalFilePath, BackupFilePath);
210209
}
211210
}
212-
213211
}
214212
}

0 commit comments

Comments
 (0)