diff --git a/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/OldStreamProviderAdapter.java b/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/OldStreamProviderAdapter.java index 623500590369..574823767d9b 100644 --- a/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/OldStreamProviderAdapter.java +++ b/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/OldStreamProviderAdapter.java @@ -27,14 +27,13 @@ final class OldStreamProviderAdapter extends StreamProvider implements CurrentUs } @Override - public boolean saveContent(@NotNull String fileSpec, @NotNull byte[] content, int size, @NotNull RoamingType roamingType, boolean async) throws IOException { - if (myRoamingType == roamingType) { - if (roamingType == RoamingType.PER_USER && StorageUtil.isProjectOrModuleFile(fileSpec)) { - return false; - } + public boolean isApplicable(@NotNull String fileSpec, @NotNull RoamingType roamingType) { + return myRoamingType == roamingType && !(roamingType == RoamingType.PER_USER && StorageUtil.isProjectOrModuleFile(fileSpec)); + } - myProvider.saveContent(fileSpec, new BufferExposingByteArrayInputStream(content, size), size, roamingType, async); - } + @Override + public boolean saveContent(@NotNull String fileSpec, @NotNull byte[] content, int size, @NotNull RoamingType roamingType, boolean async) throws IOException { + myProvider.saveContent(fileSpec, new BufferExposingByteArrayInputStream(content, size), size, roamingType, async); return false; } diff --git a/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/StateStorageManagerImpl.java b/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/StateStorageManagerImpl.java index 44cc8d94f547..186ba20c179f 100644 --- a/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/StateStorageManagerImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/StateStorageManagerImpl.java @@ -556,15 +556,23 @@ public abstract class StateStorageManagerImpl implements StateStorageManager, Di return false; } + @Override + public boolean isApplicable(@NotNull String fileSpec, @NotNull RoamingType roamingType) { + for (StreamProvider provider : myStreamProviders) { + if (provider.isApplicable(fileSpec, roamingType)) { + return true; + } + } + return false; + } + @Override public boolean saveContent(@NotNull String fileSpec, @NotNull byte[] content, int size, @NotNull RoamingType roamingType, boolean async) throws IOException { boolean result = false; for (StreamProvider streamProvider : myStreamProviders) { try { - if (streamProvider.isEnabled()) { - if (streamProvider.saveContent(fileSpec, content, size, roamingType, async)) { - result = true; - } + if (streamProvider.isEnabled() && streamProvider.isApplicable(fileSpec, roamingType) && streamProvider.saveContent(fileSpec, content, size, roamingType, async)) { + result = true; } } catch (ConnectException e) { @@ -581,7 +589,7 @@ public abstract class StateStorageManagerImpl implements StateStorageManager, Di public InputStream loadContent(@NotNull final String fileSpec, @NotNull final RoamingType roamingType) throws IOException { for (StreamProvider streamProvider : myStreamProviders) { try { - if (streamProvider.isEnabled()) { + if (streamProvider.isEnabled() && streamProvider.isApplicable(fileSpec, roamingType)) { InputStream content = streamProvider.loadContent(fileSpec, roamingType); if (content != null) { return content; @@ -603,7 +611,7 @@ public abstract class StateStorageManagerImpl implements StateStorageManager, Di public void deleteFile(@NotNull String fileSpec, @NotNull RoamingType roamingType) { for (StreamProvider streamProvider : myStreamProviders) { try { - if (streamProvider.isEnabled()) { + if (streamProvider.isEnabled() && streamProvider.isApplicable(fileSpec, roamingType)) { streamProvider.deleteFile(fileSpec, roamingType); } } @@ -616,6 +624,10 @@ public abstract class StateStorageManagerImpl implements StateStorageManager, Di @Override public String getCurrentUserName() { for (OldStreamProviderAdapter provider : myStreamProviders) { + if (!provider.isEnabled()) { + continue; + } + String userName = provider.getCurrentUserName(); if (userName != null) { return userName; diff --git a/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/StorageUtil.java b/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/StorageUtil.java index d75c56a9753c..7a1ecb73b01c 100644 --- a/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/StorageUtil.java +++ b/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/StorageUtil.java @@ -257,6 +257,10 @@ public class StorageUtil { } public static boolean sendContent(@NotNull StreamProvider provider, @NotNull String fileSpec, @NotNull Document copy, @NotNull RoamingType type, boolean async) { + if (!provider.isApplicable(fileSpec, type)) { + return false; + } + try { return doSendContent(provider, fileSpec, copy, type, async); } @@ -266,6 +270,15 @@ public class StorageUtil { } } + public static void deleteContent(@NotNull StreamProvider provider, @NotNull String fileSpec, @NotNull RoamingType type) { + if (provider.isApplicable(fileSpec, type)) { + provider.deleteFile(fileSpec, type); + } + } + + /** + * You must call {@link StreamProvider#isApplicable(String, com.intellij.openapi.components.RoamingType)} before + */ public static boolean doSendContent(StreamProvider provider, String fileSpec, Document copy, RoamingType type, boolean async) throws IOException { // we should use standard line-separator (\n) - stream provider can share file content on any OS BufferExposingByteArrayOutputStream content = documentToBytes(copy, false); diff --git a/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/StreamProvider.java b/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/StreamProvider.java index deec021f61ea..bf03cfbfc75c 100644 --- a/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/StreamProvider.java +++ b/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/StreamProvider.java @@ -14,6 +14,13 @@ public abstract class StreamProvider { public abstract boolean isEnabled(); + /** + * fileSpec Only main fileSpec, not version + */ + public boolean isApplicable(@NotNull String fileSpec, @NotNull RoamingType roamingType) { + return true; + } + /** * @param fileSpec * @param content bytes of content, size of array is not actual size of data, you must use {@code size} diff --git a/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/XmlElementStorage.java b/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/XmlElementStorage.java index 4f9ca8c8da6f..8c2c85bfa340 100644 --- a/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/XmlElementStorage.java +++ b/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/XmlElementStorage.java @@ -42,7 +42,7 @@ public abstract class XmlElementStorage implements StateStorage, Disposable { private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.components.impl.stores.XmlElementStorage"); @NonNls private static final String ATTR_NAME = "name"; - public static final String VERSION_FILE_SUFFIX = ".ver"; + private static final String VERSION_FILE_SUFFIX = ".ver"; protected TrackingPathMacroSubstitutor myPathMacroSubstitutor; @NotNull private final String myRootElementName; @@ -406,7 +406,7 @@ public abstract class XmlElementStorage implements StateStorage, Disposable { if (myStreamProvider != null && myStreamProvider.isEnabled() && (myProviderUpToDateHash == -1 || myProviderUpToDateHash != hash)) { try { //noinspection IfStatementWithIdenticalBranches - if (saveForProviders(myStreamProvider)) { + if (saveForProvider(myStreamProvider)) { //noinspection UnnecessaryReturnStatement return; } @@ -432,9 +432,12 @@ public abstract class XmlElementStorage implements StateStorage, Disposable { } } - private boolean saveForProviders(@NotNull StreamProvider streamProvider) { + private boolean saveForProvider(@NotNull StreamProvider streamProvider) { + // it is not really correctly implemented - stream provider can save not the whole document, but only filtered (per roaming type) + // but right now it is not our case, so, we should refine it later, but it not leads to bug now + boolean result = false; for (final RoamingType roamingType : RoamingType.values()) { - if (roamingType == RoamingType.DISABLED) { + if (roamingType == RoamingType.DISABLED || !streamProvider.isApplicable(myFileSpec, roamingType)) { continue; } @@ -468,20 +471,21 @@ public abstract class XmlElementStorage implements StateStorage, Disposable { } try { - boolean result = StorageUtil.doSendContent(streamProvider, myFileSpec, actualDocument, roamingType, true); + if (StorageUtil.doSendContent(streamProvider, myFileSpec, actualDocument, roamingType, true)) { + result = true; + } TObjectLongHashMap versions = loadVersions(actualDocument.getRootElement().getChildren(StorageData.COMPONENT)); if (!versions.isEmpty()) { Document versionDoc = new Document(StateStorageManagerImpl.createComponentVersionsXml(versions)); - StorageUtil.sendContent(streamProvider, myFileSpec + VERSION_FILE_SUFFIX, versionDoc, roamingType, true); + StorageUtil.doSendContent(streamProvider, myFileSpec + VERSION_FILE_SUFFIX, versionDoc, roamingType, true); } - return result; } catch (IOException e) { LOG.warn(e); } } - return false; + return result; } private boolean isHashUpToDate(final Integer hash) { diff --git a/platform/platform-impl/src/com/intellij/openapi/options/SchemesManagerImpl.java b/platform/platform-impl/src/com/intellij/openapi/options/SchemesManagerImpl.java index f02daffda795..d2a5e858f4a7 100644 --- a/platform/platform-impl/src/com/intellij/openapi/options/SchemesManagerImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/options/SchemesManagerImpl.java @@ -695,6 +695,11 @@ public class SchemesManagerImpl schemes, final UniqueFileNamesProvider fileNameProvider) throws WriteExternalException { diff --git a/platform/projectModel-impl/src/com/intellij/openapi/components/impl/stores/StorageData.java b/platform/projectModel-impl/src/com/intellij/openapi/components/impl/stores/StorageData.java index 9b1e9864b396..33fac00bcd85 100644 --- a/platform/projectModel-impl/src/com/intellij/openapi/components/impl/stores/StorageData.java +++ b/platform/projectModel-impl/src/com/intellij/openapi/components/impl/stores/StorageData.java @@ -53,7 +53,6 @@ public class StorageData { myComponentStates = new THashMap(storageData.myComponentStates); } - public void load(@NotNull Element rootElement) throws IOException { final Element[] elements = JDOMUtil.getElements(rootElement); for (Element element : elements) { diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/shelf/CompoundShelfFileProcessor.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/shelf/CompoundShelfFileProcessor.java index f01922ce8577..cb073e2c129b 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/shelf/CompoundShelfFileProcessor.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/shelf/CompoundShelfFileProcessor.java @@ -19,6 +19,7 @@ import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.PathManager; import com.intellij.openapi.application.impl.ApplicationImpl; import com.intellij.openapi.components.RoamingType; +import com.intellij.openapi.components.impl.stores.StorageUtil; import com.intellij.openapi.components.impl.stores.StreamProvider; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.util.io.FileUtil; @@ -159,12 +160,10 @@ public class CompoundShelfFileProcessor { } private static void copyFileContentToProviders(final String newFilePath, final StreamProvider serverStreamProvider, final File file) throws IOException { - if (!serverStreamProvider.isEnabled()) { - return; + if (serverStreamProvider.isEnabled() && serverStreamProvider.isApplicable(newFilePath, RoamingType.PER_USER)) { + byte[] content = FileUtil.loadFileBytes(file); + serverStreamProvider.saveContent(newFilePath, content, content.length, RoamingType.PER_USER, true); } - - byte[] content = FileUtil.loadFileBytes(file); - serverStreamProvider.saveContent(newFilePath, content, content.length, RoamingType.PER_USER, true); } private static void copyFileToStream(final InputStream stream, final File file) throws IOException { @@ -222,7 +221,7 @@ public class CompoundShelfFileProcessor { public void delete(final String name) { FileUtil.delete(new File(getBaseIODir(), name)); if (myServerStreamProvider != null && myServerStreamProvider.isEnabled()) { - myServerStreamProvider.deleteFile(FILE_SPEC + name, RoamingType.PER_USER); + StorageUtil.deleteContent(myServerStreamProvider, FILE_SPEC + name, RoamingType.PER_USER); } } } \ No newline at end of file