From 533686a01ab1b3de45262e77fdc20400842cf1ba Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Tue, 11 Sep 2012 13:25:59 +0200 Subject: [PATCH] recreate content of project/module files if it was truncated to 0 size (PY-7543) --- .../impl/stores/FileBasedStorage.java | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/FileBasedStorage.java b/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/FileBasedStorage.java index e025f0305978..14d4a8172d73 100644 --- a/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/FileBasedStorage.java +++ b/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/FileBasedStorage.java @@ -256,6 +256,9 @@ public class FileBasedStorage extends XmlElementStorage { LOG.info("Document was not loaded for " + myFileSpec + " file is " + (file == null ? "null" : "directory")); return null; } + else if (file.getLength() == 0) { + return processReadException(null); + } else { return loadDocumentImpl(file); } @@ -269,12 +272,15 @@ public class FileBasedStorage extends XmlElementStorage { } @Nullable - private Document processReadException(final Exception e) { - myBlockSavingTheContent = isProjectOrModuleFile(); + private Document processReadException(@Nullable final Exception e) { + boolean contentTruncated = e == null; + myBlockSavingTheContent = isProjectOrModuleFile() && !contentTruncated; if (!ApplicationManager.getApplication().isUnitTestMode() && !ApplicationManager.getApplication().isHeadlessEnvironment()) { - LOG.info(e); - final String message = "Cannot load settings from file '" + myFile.getPath() + "': " + e.getLocalizedMessage() + "\n" + - getInvalidContentMessage(); + if (e != null) { + LOG.info(e); + } + final String message = "Cannot load settings from file '" + myFile.getPath() + "': " + (e == null ? "content truncated" : e.getLocalizedMessage()) + "\n" + + getInvalidContentMessage(contentTruncated); Notifications.Bus.notify( new Notification(Notifications.SYSTEM_MESSAGES_GROUP_ID, "Load Settings", message, NotificationType.WARNING)); } @@ -286,8 +292,8 @@ public class FileBasedStorage extends XmlElementStorage { return myIsProjectSettings || myFileSpec.equals("$MODULE_FILE$"); } - private String getInvalidContentMessage() { - return isProjectOrModuleFile() ? "Please correct the file content" : "File content will be recreated"; + private String getInvalidContentMessage(boolean contentTruncated) { + return isProjectOrModuleFile() && !contentTruncated ? "Please correct the file content" : "File content will be recreated"; } private static Document loadDocumentImpl(final VirtualFile file) throws IOException, JDOMException {