-
Notifications
You must be signed in to change notification settings - Fork 147
Proposal: Opening/Closing Mechanism for Zip Files #1413
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
Michael5601
wants to merge
35
commits into
eclipse-platform:master
Choose a base branch
from
CodeLtDave:ZipFileImplementation
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
4d3017d
Proposal: Opening/Closing Mechanism for Zip Files
Michael5601 e200d61
remove progressMonitor and ProgressDialog
Michael5601 6475ab0
remove parametrization for tests
Michael5601 c8c3666
make static refactorings in ZipFileStore
CodeLtDave 2b6bbb8
make use of getPluginID()
CodeLtDave 828d139
remove tempFile creation when folder gets created
CodeLtDave 33c6011
change checkFileForZipHeader with header check to canZipFileBeOpened …
CodeLtDave 891d726
extract the ZipEntryFileVisitor from childEntries in its own class
CodeLtDave 86bce29
fix bug sub folders appearing on top level
CodeLtDave b4f4f5c
New test for copy bug
Michael5601 aae7724
temporary workaround for gender issues
Michael5601 f03138b
fix MoveTest
Michael5601 d1bd079
new test concurrencyTest
Michael5601 2f78e29
Introduce Lock mechanism to ZipFileStore
Michael5601 1c30966
introduce Virtual Zip Folder
CodeLtDave 10b8ac9
fix deadlock
Michael5601 e260557
delete implicit line
Michael5601 c632ff5
Add parametrization to test .jar and .war files
Michael5601 8b6d7d0
Allow WAR and JAR files
Michael5601 5cae0ba
remove Todo
Michael5601 87e0a69
remove code from RefreshLocalVisitor
Michael5601 6e1efdd
new test for move bug
Michael5601 da1b006
Revert "new test concurrencyTest"
Michael5601 129fc4b
fix move folder twice error
CodeLtDave c37d5e8
revert accidental changes
CodeLtDave 551edba
show in FileSystem for VirtualZipFolders
CodeLtDave 5e86e76
Revert "Allow WAR and JAR files"
Michael5601 585d603
make opening zip files atomic
Michael5601 4844519
add null check for locationURI
Michael5601 12c7a94
implement double click open for zip files
Michael5601 fc3ca17
Refactor tests
Michael5601 662e26c
add proper viewer refresh
Michael5601 4202dea
atomic zip file open working
Michael5601 56817fb
Refactor
Michael5601 ba2cef4
revert new file .project
Michael5601 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
...rces/bundles/org.eclipse.core.filesystem/src/org/eclipse/core/filesystem/ZipFileUtil.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 Vector Informatik GmbH and others. | ||
* | ||
* This program and the accompanying materials are made available under the terms of the Eclipse | ||
* Public License 2.0 which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: Vector Informatik GmbH - initial API and implementation | ||
*******************************************************************************/ | ||
|
||
package org.eclipse.core.filesystem; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.net.URI; | ||
import java.util.zip.ZipInputStream; | ||
import org.eclipse.core.internal.filesystem.zip.ZipFileStore; | ||
import org.eclipse.core.runtime.CoreException; | ||
|
||
/** | ||
* Utility class for zip files. | ||
* | ||
* @since 1.11 | ||
*/ | ||
public class ZipFileUtil { | ||
|
||
|
||
public static boolean isInsideOpenZipFile(IFileStore store) { | ||
return store instanceof ZipFileStore; | ||
} | ||
|
||
public static boolean isInsideOpenZipFile(URI locationURI) { | ||
IFileStore store; | ||
try { | ||
if (locationURI != null) { | ||
store = EFS.getStore(locationURI); | ||
} else { | ||
return false; | ||
} | ||
} catch (CoreException e) { | ||
return false; | ||
} | ||
return isInsideOpenZipFile(store); | ||
} | ||
|
||
/** | ||
* Determines if the given {@link IFileStore} represents an open ZIP file. | ||
* This can be used to check if operations on a ZIP file should be allowed or handled differently. | ||
* | ||
* @param store The file store to check. | ||
* @return true if the store is an instance of {@link ZipFileStore}, false otherwise. | ||
*/ | ||
public static boolean isOpenZipFile(IFileStore store) { | ||
if (isInsideOpenZipFile(store)) { | ||
ZipFileStore zipStore = (ZipFileStore) store; | ||
return zipStore.getPath().isEmpty(); //if path is empty its the root | ||
Michael5601 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
return false; | ||
} | ||
|
||
/** | ||
* @see ZipFileUtil#isOpenZipFile(IFileStore) | ||
*/ | ||
public static boolean isOpenZipFile(URI locationURI) { | ||
IFileStore store; | ||
try { | ||
store = EFS.getStore(locationURI); | ||
} catch (CoreException e) { | ||
return false; | ||
} | ||
return isOpenZipFile(store); | ||
} | ||
|
||
public static boolean isNested(URI fileURI) { | ||
if (fileURI.getScheme().contains("zip")) { //$NON-NLS-1$ | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
/** | ||
* Checks if the provided {@link InputStream} represents a ZIP archive | ||
* by attempting to open it as a ZIP archive. | ||
* This method throws {@link IOException} if the stream does not represent a valid ZIP archive. | ||
* | ||
* @param fis The {@link InputStream} of the file to check. | ||
* @throws IOException If the stream does not represent a valid ZIP archive | ||
* or an I/O error occurs during reading from the stream. | ||
*/ | ||
public static void canZipFileBeOpened(InputStream fis) throws IOException { | ||
// Use ZipInputStream to try reading the InputStream as a ZIP file | ||
try (ZipInputStream zipStream = new ZipInputStream(fis)) { | ||
// Attempt to read the first entry from the zip stream | ||
if (zipStream.getNextEntry() == null) { | ||
// If there are no entries, then it might not be a ZIP file or it's empty | ||
throw new IOException(); | ||
} | ||
// Successfully reading an entry implies it's likely a valid ZIP file | ||
} | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
...pse.core.filesystem/src/org/eclipse/core/internal/filesystem/zip/ZipEntryFileVisitor.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package org.eclipse.core.internal.filesystem.zip; | ||
|
||
import java.nio.file.FileVisitResult; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.SimpleFileVisitor; | ||
import java.nio.file.attribute.BasicFileAttributes; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.zip.ZipEntry; | ||
|
||
public class ZipEntryFileVisitor extends SimpleFileVisitor<Path> { | ||
private final Path zipRoot; | ||
private final List<ZipEntry> entryList; | ||
|
||
public ZipEntryFileVisitor(Path zipRoot) { | ||
this.zipRoot = zipRoot; | ||
this.entryList = new ArrayList<>(); | ||
} | ||
|
||
@Override | ||
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) { | ||
String entryName = zipRoot.relativize(file).toString(); | ||
if (!Files.isDirectory(file)) { | ||
ZipEntry zipEntry = new ZipEntry(entryName); | ||
zipEntry.setSize(attrs.size()); | ||
zipEntry.setTime(attrs.lastModifiedTime().toMillis()); | ||
zipEntry.setMethod(ZipEntry.DEFLATED); | ||
entryList.add(zipEntry); | ||
} else { | ||
entryList.add(new ZipEntry(entryName + "/")); //$NON-NLS-1$ | ||
} | ||
return FileVisitResult.CONTINUE; | ||
} | ||
|
||
@Override | ||
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) { | ||
if (!dir.equals(zipRoot)) { | ||
String dirName = zipRoot.relativize(dir).toString() + "/"; //$NON-NLS-1$ | ||
entryList.add(new ZipEntry(dirName)); | ||
return FileVisitResult.SKIP_SUBTREE; // Skip the subdirectories | ||
} | ||
return FileVisitResult.CONTINUE; | ||
} | ||
|
||
public List<ZipEntry> getEntries() { | ||
return entryList; | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.