]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/migration/MigrationStateImpl.java
Importing TG files creates copies of files without deleting them.
[simantics/platform.git] / bundles / org.simantics.db.layer0 / src / org / simantics / db / layer0 / migration / MigrationStateImpl.java
index fb8f8c9e7aef04f1e93f1f087ed5c297fa9879f7..3e531e368e512761cca1c4d8691d6d01c55cabc0 100644 (file)
@@ -161,8 +161,16 @@ public class MigrationStateImpl implements MigrationState {
             final boolean updateDependencies = MigrationUtils.getProperty(this, MigrationStateKeys.UPDATE_DEPENDENCIES, Boolean.TRUE);
 
             File temporaryTg = exportCurrentTgAsTemporaryFile(session, monitor);
-            if (temporaryTg != null)
-                setProperty(MigrationStateKeys.CURRENT_TGS, initializeTransferableGraphSource(temporaryTg));
+            if (temporaryTg != null) {
+                TransferableGraphSource tgs = (TransferableGraphSource)properties.get(MigrationStateKeys.CURRENT_TGS);
+                if (tgs != null)
+                    try {
+                        tgs.close();
+                    } catch (IOException e) {
+                       Logger.defaultLogError(e);
+                    }
+                setProperty(MigrationStateKeys.CURRENT_TGS, initializeTransferableGraphSource(temporaryTg, true));
+            }
 
             TransferableGraphSource tgs = getProperty(MigrationStateKeys.CURRENT_TGS);
             if (tgs != null) {
@@ -253,8 +261,11 @@ public class MigrationStateImpl implements MigrationState {
        }
 
        private TransferableGraphSource initializeTransferableGraphSource(File dataContainer) throws DatabaseException {
+               return initializeTransferableGraphSource(dataContainer, false);
+       }
+       private TransferableGraphSource initializeTransferableGraphSource(File dataContainer, boolean deleteOnClose) throws DatabaseException {
                try {
-                       StreamingTransferableGraphFileReader reader = new StreamingTransferableGraphFileReader(dataContainer);
+                       StreamingTransferableGraphFileReader reader = new StreamingTransferableGraphFileReader(dataContainer, deleteOnClose);
                        TransferableGraphSource tgs = reader.readTG();
                        setProperty(MigrationStateKeys.CURRENT_TGS_READER, reader);
                        setProperty(MigrationStateKeys.CURRENT_TGS, tgs);