Skip to content
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

Proposal: Opening/Closing Mechanism for Zip Files #8

Open
wants to merge 35 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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 Jun 11, 2024
e200d61
remove progressMonitor and ProgressDialog
Michael5601 Jun 11, 2024
6475ab0
remove parametrization for tests
Michael5601 Jun 11, 2024
c8c3666
make static refactorings in ZipFileStore
CodeLtDave Jun 11, 2024
2b6bbb8
make use of getPluginID()
CodeLtDave Jun 11, 2024
828d139
remove tempFile creation when folder gets created
CodeLtDave Jun 11, 2024
33c6011
change checkFileForZipHeader with header check to canZipFileBeOpened …
CodeLtDave Jun 11, 2024
891d726
extract the ZipEntryFileVisitor from childEntries in its own class
CodeLtDave Jun 11, 2024
86bce29
fix bug sub folders appearing on top level
CodeLtDave Jun 12, 2024
b4f4f5c
New test for copy bug
Michael5601 Jun 18, 2024
aae7724
temporary workaround for gender issues
Michael5601 Jun 24, 2024
f03138b
fix MoveTest
Michael5601 Jun 25, 2024
d1bd079
new test concurrencyTest
Michael5601 Jun 25, 2024
2f78e29
Introduce Lock mechanism to ZipFileStore
Michael5601 Jun 24, 2024
1c30966
introduce Virtual Zip Folder
CodeLtDave Jul 8, 2024
10b8ac9
fix deadlock
Michael5601 Jul 29, 2024
e260557
delete implicit line
Michael5601 Jul 30, 2024
c632ff5
Add parametrization to test .jar and .war files
Michael5601 Jul 31, 2024
8b6d7d0
Allow WAR and JAR files
Michael5601 Jul 31, 2024
5cae0ba
remove Todo
Michael5601 Aug 1, 2024
87e0a69
remove code from RefreshLocalVisitor
Michael5601 Aug 1, 2024
6e1efdd
new test for move bug
Michael5601 Aug 1, 2024
da1b006
Revert "new test concurrencyTest"
Michael5601 Aug 5, 2024
129fc4b
fix move folder twice error
CodeLtDave Aug 7, 2024
c37d5e8
revert accidental changes
CodeLtDave Aug 7, 2024
551edba
show in FileSystem for VirtualZipFolders
CodeLtDave Aug 7, 2024
5e86e76
Revert "Allow WAR and JAR files"
Michael5601 Aug 12, 2024
585d603
make opening zip files atomic
Michael5601 Aug 12, 2024
4844519
add null check for locationURI
Michael5601 Aug 13, 2024
12c7a94
implement double click open for zip files
Michael5601 Aug 13, 2024
fc3ca17
Refactor tests
Michael5601 Aug 15, 2024
662e26c
add proper viewer refresh
Michael5601 Aug 19, 2024
4202dea
atomic zip file open working
Michael5601 Aug 20, 2024
56817fb
Refactor
Michael5601 Aug 23, 2024
ba2cef4
revert new file .project
Michael5601 Aug 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions resources/bundles/org.eclipse.core.filesystem/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,11 @@
<run class="org.eclipse.core.internal.filesystem.NullFileSystem"/>
</filesystem>
</extension>
<extension
id="org.eclipse.core.filesystem.zip"
point="org.eclipse.core.filesystem.filesystems">
<filesystem scheme="zip">
<run class="org.eclipse.core.internal.filesystem.zip.ZipFileSystem"/>
</filesystem>
</extension>
</plugin>
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
}
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
}
}
}
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;
}
}
Loading