mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
ability to cancel write to local file
This commit is contained in:
+3
-2
@@ -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
|
||||
|
||||
+6
-2
@@ -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
|
||||
|
||||
+3
-3
@@ -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 {
|
||||
|
||||
+1
-1
@@ -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;
|
||||
|
||||
+12
-7
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user