ability to cancel write to local file

This commit is contained in:
Vladimir Krivosheev
2013-09-18 07:37:54 +02:00
parent 6999b95ddf
commit c6e955efa8
5 changed files with 25 additions and 15 deletions
@@ -27,14 +27,15 @@ public final class OldStreamProviderAdapter extends StreamProvider implements Cu
}
@Override
public void saveContent(@NotNull String fileSpec, @NotNull byte[] content, int size, @NotNull RoamingType roamingType, boolean async) throws IOException {
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;
return false;
}
myProvider.saveContent(fileSpec, new BufferExposingByteArrayInputStream(content, size), size, roamingType, async);
}
return false;
}
@Nullable
@@ -90,11 +90,14 @@ public abstract class StateStorageManagerImpl implements StateStorageManager, Di
}
@Override
public void saveContent(@NotNull String fileSpec, @NotNull byte[] content, int size, @NotNull RoamingType roamingType, boolean async) throws IOException {
public boolean saveContent(@NotNull String fileSpec, @NotNull byte[] content, int size, @NotNull RoamingType roamingType, boolean async) throws IOException {
boolean result = false;
for (StreamProvider streamProvider : getStreamProviders()) {
try {
if (streamProvider.isEnabled()) {
streamProvider.saveContent(fileSpec, content, size, roamingType, async);
if (streamProvider.saveContent(fileSpec, content, size, roamingType, async)) {
result = true;
}
}
}
catch (ConnectException e) {
@@ -104,6 +107,7 @@ public abstract class StateStorageManagerImpl implements StateStorageManager, Di
LOG.debug(e);
}
}
return result;
}
@Override
@@ -256,14 +256,14 @@ public class StorageUtil {
}
}
public static void sendContent(@NotNull StreamProvider provider, @NotNull String fileSpec, @NotNull Document copy, @NotNull RoamingType type, boolean async) throws IOException {
public static boolean sendContent(@NotNull StreamProvider provider, @NotNull String fileSpec, @NotNull Document copy, @NotNull RoamingType type, boolean async) throws IOException {
if (!provider.isEnabled()) {
return;
return false;
}
// we should use standard line-separator (\n) - stream provider can share file content on any OS
BufferExposingByteArrayOutputStream content = documentToBytes(copy, false);
provider.saveContent(fileSpec, content.getInternalBuffer(), content.size(), type, async);
return provider.saveContent(fileSpec, content.getInternalBuffer(), content.size(), type, async);
}
public static void logStateDiffInfo(Set<Pair<VirtualFile, StateStorage>> changedFiles, Set<String> componentNames) throws IOException {
@@ -21,7 +21,7 @@ public abstract class StreamProvider {
* @param roamingType
* @param async
*/
public abstract void saveContent(@NotNull String fileSpec, @NotNull byte[] content, int size, @NotNull RoamingType roamingType, boolean async) throws IOException;
public abstract boolean saveContent(@NotNull String fileSpec, @NotNull byte[] content, int size, @NotNull RoamingType roamingType, boolean async) throws IOException;
@Nullable
public abstract InputStream loadContent(@NotNull String fileSpec, @NotNull RoamingType roamingType) throws IOException;
@@ -405,7 +405,11 @@ public abstract class XmlElementStorage implements StateStorage, Disposable {
try {
if (myStreamProvider != null && myStreamProvider.isEnabled() && (myProviderUpToDateHash == -1 || myProviderUpToDateHash != hash)) {
try {
saveForProviders(myStreamProvider);
//noinspection IfStatementWithIdenticalBranches
if (saveForProviders(myStreamProvider)) {
//noinspection UnnecessaryReturnStatement
return;
}
}
finally {
myProviderUpToDateHash = hash;
@@ -419,10 +423,8 @@ public abstract class XmlElementStorage implements StateStorage, Disposable {
private void saveLocally(final Integer hash) {
try {
if (!isHashUpToDate(hash)) {
if (_needsSave(hash)) {
doSave();
}
if (!isHashUpToDate(hash) && _needsSave(hash)) {
doSave();
}
}
finally {
@@ -430,7 +432,7 @@ public abstract class XmlElementStorage implements StateStorage, Disposable {
}
}
private void saveForProviders(@NotNull StreamProvider streamProvider) {
private boolean saveForProviders(@NotNull StreamProvider streamProvider) {
for (final RoamingType roamingType : RoamingType.values()) {
if (roamingType == RoamingType.DISABLED) {
continue;
@@ -466,17 +468,20 @@ public abstract class XmlElementStorage implements StateStorage, Disposable {
}
try {
StorageUtil.sendContent(streamProvider, myFileSpec, actualDocument, roamingType, true);
boolean result = StorageUtil.sendContent(streamProvider, myFileSpec, actualDocument, roamingType, true);
TObjectLongHashMap<String> 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);
}
return result;
}
catch (IOException e) {
LOG.warn(e);
}
}
return false;
}
private boolean isHashUpToDate(final Integer hash) {