From 6de641031fb304f44a3bf4e9b234c1bbd9cd0231 Mon Sep 17 00:00:00 2001 From: Michael Bangas Date: Tue, 20 Aug 2024 12:22:21 +0200 Subject: [PATCH] atomic zip file open working --- .../core/resources/ZipFileTransformer.java | 41 +++++++------------ 1 file changed, 15 insertions(+), 26 deletions(-) diff --git a/resources/bundles/org.eclipse.core.resources/src/org/eclipse/core/resources/ZipFileTransformer.java b/resources/bundles/org.eclipse.core.resources/src/org/eclipse/core/resources/ZipFileTransformer.java index 2dab9638c6b..54c2d06e55e 100644 --- a/resources/bundles/org.eclipse.core.resources/src/org/eclipse/core/resources/ZipFileTransformer.java +++ b/resources/bundles/org.eclipse.core.resources/src/org/eclipse/core/resources/ZipFileTransformer.java @@ -21,6 +21,7 @@ import org.eclipse.core.filesystem.IFileStore; import org.eclipse.core.filesystem.URIUtil; import org.eclipse.core.filesystem.ZipFileUtil; +import org.eclipse.core.internal.resources.Resource; import org.eclipse.core.internal.resources.Workspace; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; @@ -46,29 +47,19 @@ public class ZipFileTransformer { * */ public static void closeZipFile(IFolder folder) throws URISyntaxException, CoreException { - Workspace workspace = ((Workspace) folder.getWorkspace()); IProject project = folder.getProject(); - final ISchedulingRule rule = workspace.getRuleFactory().createRule(project); - IWorkspaceRunnable runnable = monitor -> { - try { - URI zipURI = new URI(folder.getLocationURI().getQuery()); + URI zipURI = new URI(folder.getLocationURI().getQuery()); + IFileStore parentStore = EFS.getStore(folder.getParent().getLocationURI()); + URI childURI = parentStore.getChild(folder.getName()).toURI(); - IFileStore parentStore = EFS.getStore(folder.getParent().getLocationURI()); - URI childURI = parentStore.getChild(folder.getName()).toURI(); - if (URIUtil.equals(zipURI, childURI)) { - folder.delete(IResource.CLOSE_ZIP_FILE, null); - project.refreshLocal(IResource.DEPTH_INFINITE, null); - } else { - throw new CoreException(new Status(IStatus.ERROR, ResourcesPlugin.PI_RESOURCES, - "Closing of Zip File " + folder.getName() //$NON-NLS-1$ - + " failed because the Zip File is not local.")); //$NON-NLS-1$ - } - } catch (URISyntaxException e) { - throw new CoreException(new Status(IStatus.ERROR, ResourcesPlugin.PI_RESOURCES, e.getMessage())); - } - }; - workspace.run(runnable, rule, IWorkspace.AVOID_UPDATE, null); - project.refreshLocal(IResource.DEPTH_INFINITE, null); + if (URIUtil.equals(zipURI, childURI)) { + folder.delete(IResource.CLOSE_ZIP_FILE, null); + project.refreshLocal(IResource.DEPTH_INFINITE, null); + } else { + throw new CoreException(new Status(IStatus.ERROR, ResourcesPlugin.PI_RESOURCES, + "Closing of Zip File " + folder.getName() //$NON-NLS-1$ + + " failed because the Zip File is not local.")); //$NON-NLS-1$ + } } /** @@ -108,12 +99,11 @@ public static void openZipFile(IFile file, boolean backgroundRefresh) IWorkspaceRunnable runnable = monitor -> { try (InputStream fis = file.getContents()) { ZipFileUtil.canZipFileBeOpened(fis); - // Additional operations can continue here if header is correct URI zipURI = new URI("zip", null, "/", file.getLocationURI().toString(), null); //$NON-NLS-1$ //$NON-NLS-2$ IFolder link = file.getParent().getFolder(IPath.fromOSString(file.getName())); - int flags = backgroundRefresh ? IResource.REPLACE | IResource.BACKGROUND_REFRESH : IResource.REPLACE; - - link.createLink(zipURI, flags, monitor); + ((Resource) file).deleteResource(false, null); + workspace.broadcastPostChange(); + link.createLink(zipURI, IResource.BACKGROUND_REFRESH, monitor); project.refreshLocal(IResource.DEPTH_INFINITE, monitor); } catch (IOException e) { if (e instanceof ZipException && e.getMessage().equals("encrypted ZIP entry not supported")) { //$NON-NLS-1$ @@ -127,7 +117,6 @@ public static void openZipFile(IFile file, boolean backgroundRefresh) new Status(IStatus.ERROR, ResourcesPlugin.PI_RESOURCES, "Zip File could not be opened")); //$NON-NLS-1$ } }; - workspace.run(runnable, rule, IWorkspace.AVOID_UPDATE, null); project.refreshLocal(IResource.DEPTH_INFINITE, null); }