Skip to content

Commit

Permalink
fix for location udig bug-168
Browse files Browse the repository at this point in the history
(https://bugs.locationtech.org/show_bug.cgi?id=168) related to Map file
deletion from disk 

Signed-off-by: Nikolaos Pringouris <[email protected]>
  • Loading branch information
nprigour authored and fgdrf committed Aug 23, 2017
1 parent 9d1d8f6 commit ddf5609
Showing 1 changed file with 22 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@

import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.Platform;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.jface.action.IAction;
Expand All @@ -59,6 +60,9 @@
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PlatformUI;

import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang.StringUtils;
import org.opengis.feature.simple.SimpleFeature;

/**
Expand Down Expand Up @@ -287,14 +291,14 @@ private Pair<Boolean, Integer> dialog( int size, String deleteOne, String name,

// START TEMPORARY NEW CODE
boolean delete = MessageDialog.openConfirm( Display.getCurrent().getActiveShell(), Messages.Delete_delete, message );
boolean deleteFiles = false;
boolean deleteFiles = getDoDelete();
// END TEMPORARY NEW CODE


if( delete ){
if (deleteFiles != getDoDelete()) {
setDoDelete(deleteFiles);
}
//if (deleteFiles != getDoDelete()) {
// setDoDelete(deleteFiles);
//}
return Pair.create(deleteFiles, Window.OK);
} else {
// Window.CANCEL
Expand Down Expand Up @@ -344,12 +348,18 @@ protected final void doDelete( ProjectElement element, boolean deleteFiles, int
if (resource == null) {
return;
}
String path = resource.getURI().toFileString();
URI resourceUri = resource.getURI();
String path = resourceUri.toFileString();
resource.unload();
if (resourceUri.hasAuthority()) {
path = StringUtils.removeStart(path, "//");
}
/*
int lastIndexOf = path.lastIndexOf('/');
if (lastIndexOf == -1)
lastIndexOf = path.length();
path = path.substring(0, lastIndexOf);
*/
final File file = new File(path);
deleteFile(file);
} catch (Exception e) {
Expand Down Expand Up @@ -420,12 +430,19 @@ protected final void doDelete( Project project, boolean deleteProjectFiles, int
try {
resourceSet.getResources().remove(resource);
resource.unload();
/*
int lastIndexOf = path.lastIndexOf('/');
if (lastIndexOf == -1)
lastIndexOf = path.length();
path = path.substring(0, lastIndexOf);
*/
final File file = new File(path);
deleteFile(file);
//also delete the directory containing the files
String dirPath = FilenameUtils.getFullPathNoEndSeparator(path);
if (dirPath.endsWith(".udig")) {
deleteFile(new File(dirPath));
}
} catch (Exception e) {
ProjectUIPlugin.log("Error deleting project file", e); //$NON-NLS-1$
}
Expand Down

0 comments on commit ddf5609

Please sign in to comment.