Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion src/SyncTrayzor/Services/Config/ConfigurationProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ public void Initialize(Configuration defaultConfiguration)
}

// This is duplicated between here and ConfigurationApplicator, and it's ugly.
var expandedSyncthingPath = string.IsNullOrWhiteSpace(currentConfig.SyncthingCustomPath) ?
var usingDefaultSyncthingPath = string.IsNullOrWhiteSpace(currentConfig.SyncthingCustomPath);
var expandedSyncthingPath = usingDefaultSyncthingPath ?
paths.DefaultSyncthingPath :
pathTransformer.MakeAbsolute(currentConfig.SyncthingCustomPath);

Expand All @@ -135,6 +136,20 @@ public void Initialize(Configuration defaultConfiguration)
filesystem.Copy(paths.SyncthingBackupPath, expandedSyncthingPath);
SyncthingInstalled = true;
}
else if (usingDefaultSyncthingPath &&
!String.Equals(Path.GetFullPath(expandedSyncthingPath), Path.GetFullPath(paths.SyncthingBackupPath), StringComparison.OrdinalIgnoreCase) &&
filesystem.FileExists(paths.SyncthingBackupPath))
{
var installedVersion = filesystem.GetFileVersion(expandedSyncthingPath);
var bundledVersion = filesystem.GetFileVersion(paths.SyncthingBackupPath);
if (installedVersion != null && bundledVersion != null && bundledVersion > installedVersion)
{
logger.Info("Updating the default Syncthing binary at {Path} from {InstalledVersion} to bundled version {BundledVersion}",
expandedSyncthingPath, installedVersion, bundledVersion);
filesystem.Copy(paths.SyncthingBackupPath, expandedSyncthingPath, overwrite: true);
SyncthingInstalled = true;
}
}

if (updateConfigInstallCount)
{
Expand Down
12 changes: 10 additions & 2 deletions src/SyncTrayzor/Services/FilesystemProvider.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using SyncTrayzor.Utils;
using System;
using System.Diagnostics;
using System.IO;
using System.Collections.Generic;

Expand All @@ -13,7 +14,8 @@ public interface IFilesystemProvider
FileStream Open(string path, FileMode fileMode, FileAccess fileAccess, FileShare fileShare);
FileStream CreateAtomic(string path);
FileStream OpenRead(string path);
void Copy(string from, string to);
void Copy(string from, string to, bool overwrite = false);
Version GetFileVersion(string path);
void MoveFile(string from, string to);
void CreateDirectory(string path);
void DeleteFile(string path);
Expand Down Expand Up @@ -48,7 +50,13 @@ public class FilesystemProvider : IFilesystemProvider

public FileStream OpenRead(string path) => File.OpenRead(path);

public void Copy(string from, string to) => File.Copy(from, to);
public void Copy(string from, string to, bool overwrite = false) => File.Copy(from, to, overwrite);

public Version GetFileVersion(string path)
{
var fileVersion = FileVersionInfo.GetVersionInfo(path).FileVersion?.Trim();
return Version.TryParse(fileVersion, out var version) ? version : null;
}
Comment on lines +55 to +59

public void MoveFile(string from, string to) => File.Move(from, to);

Expand Down