From 32efef3866bf82d94d0212cb88d96f4facc3b493 Mon Sep 17 00:00:00 2001 From: Sergey Pak Date: Tue, 8 Apr 2025 14:24:17 +0200 Subject: [PATCH] [settingsSync] return actual pushedVersion during sendSnapshotFile() GitOrigin-RevId: 979cb8d84aaffa51f7e5a8c43f1e599d855ba6ba --- .../core/AbstractServerCommunicator.kt | 47 +++++++++---------- 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/platform/settings-sync-core/src/com/intellij/settingsSync/core/AbstractServerCommunicator.kt b/platform/settings-sync-core/src/com/intellij/settingsSync/core/AbstractServerCommunicator.kt index aa2580557f2d..ed20b9766dbf 100644 --- a/platform/settings-sync-core/src/com/intellij/settingsSync/core/AbstractServerCommunicator.kt +++ b/platform/settings-sync-core/src/com/intellij/settingsSync/core/AbstractServerCommunicator.kt @@ -116,38 +116,37 @@ abstract class AbstractServerCommunicator() : SettingsSyncRemoteCommunicator { val defaultMessage = "Unknown during checking $CROSS_IDE_SYNC_MARKER_FILE" try { snapshotFilePath = currentSnapshotFilePath()?.first ?: return SettingsSyncPushResult.Error(defaultMessage) - } - catch (ioe: IOException) { - return SettingsSyncPushResult.Error(ioe.message ?: defaultMessage) - } - val versionToPush: String? - if (force) { - // get the latest server version: pushing with it will overwrite the file in any case - versionToPush = getLatestVersion(snapshotFilePath) - writeFileInternal(snapshotFilePath, versionToPush, inputStream) - } - else { - if (knownServerVersion != null) { - versionToPush = knownServerVersion + val versionToPush: String? + if (force) { + // get the latest server version: pushing with it will overwrite the file in any case + versionToPush = getLatestVersion(snapshotFilePath) } else { - val serverVersion = getLatestVersion(snapshotFilePath) - if (serverVersion == null) { - // no file on the server => just push it there - versionToPush = null + if (knownServerVersion != null) { + versionToPush = knownServerVersion } else { - // we didn't store the server version locally yet => reject the push to avoid overwriting the server version; - // the next update after the rejected push will store the version information, and subsequent push will be successful. - return SettingsSyncPushResult.Rejected + val serverVersion = getLatestVersion(snapshotFilePath) + if (serverVersion == null) { + // no file on the server => just push it there + versionToPush = null + } + else { + // we didn't store the server version locally yet => reject the push to avoid overwriting the server version; + // the next update after the rejected push will store the version information, and subsequent push will be successful. + return SettingsSyncPushResult.Rejected + } } } - writeFileInternal(snapshotFilePath, versionToPush, inputStream) - } - // errors are thrown as exceptions, and are handled above - return SettingsSyncPushResult.Success(versionToPush) + val pushedVersion = writeFileInternal(snapshotFilePath, versionToPush, inputStream) + // errors are thrown as exceptions, and are handled above + return SettingsSyncPushResult.Success(pushedVersion) + } + catch (e: Throwable) { + return SettingsSyncPushResult.Error(e.message ?: defaultMessage) + } } override fun checkServerState(): ServerState {