@@ -26,7 +26,7 @@ public static BorgInstallation getInstance() {
2626 return instance ;
2727 }
2828
29- private BorgVersion borgVersion = new BorgVersion ();
29+ private BorgConfig borgConfig = new BorgConfig ();
3030
3131 public void initialize () {
3232 Configuration configuration = ConfigurationHandler .getConfiguration ();
@@ -35,24 +35,30 @@ public void initialize() {
3535 return ;
3636 }
3737 }
38- borgVersion . setBinariesDownloadVersion (configuration .getBorgVersion ());
38+ borgConfig . setVersion (configuration .getBorgVersion ());
3939 initialize (getBinary (RunningMode .getOSType ()));
40- if (!borgVersion .isVersionOK ()) {
41- log .warn ("No working borg version found. Please configure a borg version with minimal version '" + borgVersion .getMinimumRequiredBorgVersion () + "'." );
40+ if (!borgConfig .isVersionOK ()) {
41+ log .warn ("No working borg version found. Please configure a borg version with minimal version '" + borgConfig .getMinimumRequiredBorgVersion () + "'." );
4242 }
4343 }
4444
4545 /**
4646 * Configures a new borg configuration if modifications was done.
4747 *
4848 * @param newConfiguration The new configuration with the (new) borg command to use (executable).
49- * @param borgBinary The id of the borg binary (Mac OS X, Linux 64, manual etc.)
49+ * @param newBorgConfig The new config, including the id of the borg binary (Mac OS X, Linux 64, manual etc.) and version.
5050 */
51- public void configure (ServerConfiguration newConfiguration , String borgBinary ) {
51+ public void configure (ServerConfiguration newConfiguration , BorgConfig newBorgConfig ) {
5252 ServerConfiguration configuration = ServerConfiguration .get ();
53- boolean borgBinaryChanged = !StringUtils .equals (borgVersion .getBorgBinary (), borgBinary );
54- borgVersion .setBorgBinary (borgBinary ); // Update borg binary (if changed).
55- boolean manualBorgCommand = "manual" .equals (borgBinary );
53+ String oldBorgBinary = borgConfig .getBorgBinary ();
54+ String oldVersion = borgConfig .getVersion ();
55+ String newBorgBinary = newBorgConfig .getBorgBinary ();
56+ String newVersion = newConfiguration .getBorgVersion ();
57+ boolean borgBinaryChanged = !StringUtils .equals (oldBorgBinary , newBorgBinary ) ||
58+ !StringUtils .equals (oldVersion , newVersion );
59+ borgConfig .setBorgBinary (newBorgBinary ); // Update borg binary (if changed).
60+ borgConfig .setVersion (newVersion );
61+ boolean manualBorgCommand = "manual" .equals ( newBorgConfig .getBorgBinary ());
5662 if (manualBorgCommand ) {
5763 boolean borgCommandChanged = !StringUtils .equals (newConfiguration .getBorgCommand (), configuration .getBorgCommand ());
5864 if (borgCommandChanged ) {
@@ -61,9 +67,16 @@ public void configure(ServerConfiguration newConfiguration, String borgBinary) {
6167 }
6268 } else {
6369 if (borgBinaryChanged ) {
64- initialize (getBinary (borgBinary ));
70+ initialize (getBinary (newBorgBinary ));
6571 }
6672 newConfiguration .setBorgCommand (configuration .getBorgCommand ()); // borg command of this class overwrites new configuration for mode != 'manual'.
73+ newConfiguration .setBorgVersion (newVersion );
74+ if (!StringUtils .equals (oldVersion , newVersion )) {
75+ log .info ("Version '" + oldVersion + "' -> '" + newVersion + "'." );
76+ }
77+ if (!StringUtils .equals (oldBorgBinary , newBorgBinary )) {
78+ log .info ("Binary '" + oldBorgBinary + "' -> '" + newBorgBinary + "'." );
79+ }
6780 }
6881 }
6982
@@ -75,17 +88,17 @@ private boolean initialize(String[] binary) {
7588 File file = download (binary );
7689 if (file != null ) {
7790 configuration .setBorgCommand (file .getAbsolutePath ());
78- borgVersion .setBorgBinary (binary [0 ]);
91+ borgConfig .setBorgBinary (binary [0 ]);
7992 }
8093 return version (configuration );
8194 }
8295
8396 private boolean version (Configuration configuration ) {
8497 String borgCommand = configuration .getBorgCommand ();
8598 if (StringUtils .isNotBlank (borgCommand )) {
86- for (String [] borgBinary : borgVersion .getBorgBinaries ()) {
99+ for (String [] borgBinary : borgConfig .getBorgBinaries ()) {
87100 if (borgCommand .contains (borgBinary [0 ])) {
88- borgVersion .setBorgBinary (borgBinary [0 ]);
101+ borgConfig .setBorgBinary (borgBinary [0 ]);
89102 break ;
90103 }
91104 }
@@ -94,22 +107,22 @@ private boolean version(Configuration configuration) {
94107 boolean versionOK = false ;
95108 String msg = null ;
96109 if (versionString != null ) {
97- borgVersion .setVersion (versionString );
98- int cmp = BorgVersion .compareVersions (versionString , borgVersion .getMinimumRequiredBorgVersion ());
110+ borgConfig .setVersion (versionString );
111+ int cmp = BorgConfig .compareVersions (versionString , borgConfig .getMinimumRequiredBorgVersion ());
99112 if (cmp < 0 ) {
100- msg = "Found borg version '" + versionString + "' is less than minimum required version '" + borgVersion .getMinimumRequiredBorgVersion () + "'." ;
113+ msg = "Found borg version '" + versionString + "' is less than minimum required version '" + borgConfig .getMinimumRequiredBorgVersion () + "'." ;
101114 log .info (msg );
102115 } else {
103116 versionOK = true ;
104- msg = "Found borg '" + configuration .getBorgCommand () + "', version: " + versionString + " (equals to or newer than '" + borgVersion .getMinimumRequiredBorgVersion ()
117+ msg = "Found borg '" + configuration .getBorgCommand () + "', version: " + versionString + " (equals to or newer than '" + borgConfig .getMinimumRequiredBorgVersion ()
105118 + "', OK)." ;
106119 log .info (msg );
107120 }
108121 } else {
109122 msg = "Couldn't execute borg command '" + configuration .getBorgCommand () + "'." ;
110123 }
111- borgVersion .setVersionOK (versionOK );
112- borgVersion .setStatusMessage (msg );
124+ borgConfig .setVersionOK (versionOK );
125+ borgConfig .setStatusMessage (msg );
113126 return versionOK ;
114127 }
115128
@@ -133,7 +146,7 @@ private String[] getBinary(String os) {
133146 if (os == null ) {
134147 return null ;
135148 }
136- for (String [] binary : borgVersion .getBorgBinaries ()) {
149+ for (String [] binary : borgConfig .getBorgBinaries ()) {
137150 if (binary [0 ].contains (os )) {
138151 return binary ;
139152 }
@@ -156,7 +169,7 @@ private File download(String[] binary) {
156169 // File already downloaded, nothing to do.
157170 return file ;
158171 }
159- String url = borgVersion .getBinariesDownloadUrl () + getDownloadFilename (binary );
172+ String url = borgConfig .getBinariesDownloadUrl () + getDownloadFilename (binary );
160173 log .info ("Trying to download borg binary '" + binary [0 ] + "' (" + binary [1 ] + ") from url: " + url + "..." );
161174 HttpClientBuilder builder = HttpClients .custom ()
162175 .setDefaultRequestConfig (RequestConfig .custom ()
@@ -186,7 +199,7 @@ private File getBinaryFile(String[] binary) {
186199 log .info ("Creating binary directory: " + dir .getAbsolutePath ());
187200 dir .mkdirs ();
188201 }
189- return new File (dir , getDownloadFilename (binary ) + "-" + borgVersion . getBinariesDownloadVersion ());
202+ return new File (dir , getDownloadFilename (binary ) + "-" + borgConfig . getVersion ());
190203 }
191204
192205 private String getDownloadFilename (String [] binary ) {
@@ -196,7 +209,7 @@ private String getDownloadFilename(String[] binary) {
196209 private BorgInstallation () {
197210 }
198211
199- public BorgVersion getBorgVersion () {
200- return this .borgVersion ;
212+ public BorgConfig getBorgConfig () {
213+ return this .borgConfig ;
201214 }
202215}
0 commit comments