Search in sources :

Example 1 with VFSLockManager

use of org.olat.core.util.vfs.VFSLockManager in project OpenOLAT by OpenOLAT.

the class ZipUtil method checkLockedFileBeforeUnzip.

// unzip
/**
 * Check if a file in the zip is already in the path
 * @param zipLeaf
 * @param targetDir
 * @param identity
 * @param isAdmin
 * @return the list of files which already exist
 */
public static List<String> checkLockedFileBeforeUnzip(VFSLeaf zipLeaf, VFSContainer targetDir, Identity identity, Roles isAdmin) {
    List<String> lockedFiles = new ArrayList<String>();
    InputStream in = zipLeaf.getInputStream();
    ZipInputStream oZip = new ZipInputStream(in);
    VFSLockManager vfsLockManager = CoreSpringFactory.getImpl(VFSLockManager.class);
    try {
        // unzip files
        ZipEntry oEntr = oZip.getNextEntry();
        while (oEntr != null) {
            if (oEntr.getName() != null && !oEntr.getName().startsWith(DIR_NAME__MACOSX)) {
                if (oEntr.isDirectory()) {
                    // skip MacOSX specific metadata directory
                    // directories aren't locked
                    oZip.closeEntry();
                    oEntr = oZip.getNextEntry();
                    continue;
                } else {
                    // search file
                    VFSContainer createIn = targetDir;
                    String name = oEntr.getName();
                    // check if entry has directories which did not show up as
                    // directories above
                    int dirSepIndex = name.lastIndexOf('/');
                    if (dirSepIndex == -1) {
                        // try it windows style, backslash is also valid format
                        dirSepIndex = name.lastIndexOf('\\');
                    }
                    if (dirSepIndex > 0) {
                        // get subdirs
                        createIn = getAllSubdirs(targetDir, name.substring(0, dirSepIndex), identity, false);
                        if (createIn == null) {
                            // sub directories don't exist, and aren't locked
                            oZip.closeEntry();
                            oEntr = oZip.getNextEntry();
                            continue;
                        }
                        name = name.substring(dirSepIndex + 1);
                    }
                    VFSLeaf newEntry = (VFSLeaf) createIn.resolve(name);
                    if (vfsLockManager.isLockedForMe(newEntry, identity, isAdmin)) {
                        lockedFiles.add(name);
                    }
                }
            }
            oZip.closeEntry();
            oEntr = oZip.getNextEntry();
        }
    } catch (IOException e) {
        return null;
    } finally {
        FileUtils.closeSafely(oZip);
        FileUtils.closeSafely(in);
    }
    return lockedFiles;
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) ZipInputStream(java.util.zip.ZipInputStream) BufferedInputStream(java.io.BufferedInputStream) ZipInputStream(java.util.zip.ZipInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ZipEntry(java.util.zip.ZipEntry) VFSContainer(org.olat.core.util.vfs.VFSContainer) ArrayList(java.util.ArrayList) IOException(java.io.IOException) VFSLockManager(org.olat.core.util.vfs.VFSLockManager)

Example 2 with VFSLockManager

use of org.olat.core.util.vfs.VFSLockManager in project openolat by klemens.

the class ZipUtil method checkLockedFileBeforeUnzipNonStrict.

/**
 * @param zipLeaf
 * @param targetDir
 * @param identity
 * @param roles
 * @return
 */
public static List<String> checkLockedFileBeforeUnzipNonStrict(VFSLeaf zipLeaf, VFSContainer targetDir, Identity identity, Roles roles) {
    List<String> lockedFiles = new ArrayList<String>();
    InputStream in = zipLeaf.getInputStream();
    net.sf.jazzlib.ZipInputStream oZip = new net.sf.jazzlib.ZipInputStream(in);
    VFSLockManager vfsLockManager = CoreSpringFactory.getImpl(VFSLockManager.class);
    try {
        // unzip files
        net.sf.jazzlib.ZipEntry oEntr = oZip.getNextEntry();
        while (oEntr != null) {
            if (oEntr.getName() != null && !oEntr.getName().startsWith(DIR_NAME__MACOSX)) {
                if (oEntr.isDirectory()) {
                    // skip MacOSX specific metadata directory
                    // directories aren't locked
                    oZip.closeEntry();
                    oEntr = oZip.getNextEntry();
                    continue;
                } else {
                    // search file
                    VFSContainer createIn = targetDir;
                    String name = oEntr.getName();
                    // check if entry has directories which did not show up as
                    // directories above
                    int dirSepIndex = name.lastIndexOf('/');
                    if (dirSepIndex == -1) {
                        // try it windows style, backslash is also valid format
                        dirSepIndex = name.lastIndexOf('\\');
                    }
                    if (dirSepIndex > 0) {
                        // get subdirs
                        createIn = getAllSubdirs(targetDir, name.substring(0, dirSepIndex), identity, false);
                        if (createIn == null) {
                            // sub directories don't exist, and aren't locked
                            oZip.closeEntry();
                            oEntr = oZip.getNextEntry();
                            continue;
                        }
                        name = name.substring(dirSepIndex + 1);
                    }
                    VFSLeaf newEntry = (VFSLeaf) createIn.resolve(name);
                    if (vfsLockManager.isLockedForMe(newEntry, identity, roles)) {
                        lockedFiles.add(name);
                    }
                }
            }
            oZip.closeEntry();
            oEntr = oZip.getNextEntry();
        }
    } catch (IOException e) {
        return null;
    } finally {
        FileUtils.closeSafely(oZip);
        FileUtils.closeSafely(in);
    }
    return lockedFiles;
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) BufferedInputStream(java.io.BufferedInputStream) ZipInputStream(java.util.zip.ZipInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) VFSContainer(org.olat.core.util.vfs.VFSContainer) ArrayList(java.util.ArrayList) IOException(java.io.IOException) ZipInputStream(java.util.zip.ZipInputStream) VFSLockManager(org.olat.core.util.vfs.VFSLockManager)

Example 3 with VFSLockManager

use of org.olat.core.util.vfs.VFSLockManager in project OpenOLAT by OpenOLAT.

the class ZipUtil method checkLockedFileBeforeUnzipNonStrict.

/**
 * @param zipLeaf
 * @param targetDir
 * @param identity
 * @param roles
 * @return
 */
public static List<String> checkLockedFileBeforeUnzipNonStrict(VFSLeaf zipLeaf, VFSContainer targetDir, Identity identity, Roles roles) {
    List<String> lockedFiles = new ArrayList<String>();
    InputStream in = zipLeaf.getInputStream();
    net.sf.jazzlib.ZipInputStream oZip = new net.sf.jazzlib.ZipInputStream(in);
    VFSLockManager vfsLockManager = CoreSpringFactory.getImpl(VFSLockManager.class);
    try {
        // unzip files
        net.sf.jazzlib.ZipEntry oEntr = oZip.getNextEntry();
        while (oEntr != null) {
            if (oEntr.getName() != null && !oEntr.getName().startsWith(DIR_NAME__MACOSX)) {
                if (oEntr.isDirectory()) {
                    // skip MacOSX specific metadata directory
                    // directories aren't locked
                    oZip.closeEntry();
                    oEntr = oZip.getNextEntry();
                    continue;
                } else {
                    // search file
                    VFSContainer createIn = targetDir;
                    String name = oEntr.getName();
                    // check if entry has directories which did not show up as
                    // directories above
                    int dirSepIndex = name.lastIndexOf('/');
                    if (dirSepIndex == -1) {
                        // try it windows style, backslash is also valid format
                        dirSepIndex = name.lastIndexOf('\\');
                    }
                    if (dirSepIndex > 0) {
                        // get subdirs
                        createIn = getAllSubdirs(targetDir, name.substring(0, dirSepIndex), identity, false);
                        if (createIn == null) {
                            // sub directories don't exist, and aren't locked
                            oZip.closeEntry();
                            oEntr = oZip.getNextEntry();
                            continue;
                        }
                        name = name.substring(dirSepIndex + 1);
                    }
                    VFSLeaf newEntry = (VFSLeaf) createIn.resolve(name);
                    if (vfsLockManager.isLockedForMe(newEntry, identity, roles)) {
                        lockedFiles.add(name);
                    }
                }
            }
            oZip.closeEntry();
            oEntr = oZip.getNextEntry();
        }
    } catch (IOException e) {
        return null;
    } finally {
        FileUtils.closeSafely(oZip);
        FileUtils.closeSafely(in);
    }
    return lockedFiles;
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) BufferedInputStream(java.io.BufferedInputStream) ZipInputStream(java.util.zip.ZipInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) VFSContainer(org.olat.core.util.vfs.VFSContainer) ArrayList(java.util.ArrayList) IOException(java.io.IOException) ZipInputStream(java.util.zip.ZipInputStream) VFSLockManager(org.olat.core.util.vfs.VFSLockManager)

Example 4 with VFSLockManager

use of org.olat.core.util.vfs.VFSLockManager in project openolat by klemens.

the class ZipUtil method checkLockedFileBeforeUnzip.

// unzip
/**
 * Check if a file in the zip is already in the path
 * @param zipLeaf
 * @param targetDir
 * @param identity
 * @param isAdmin
 * @return the list of files which already exist
 */
public static List<String> checkLockedFileBeforeUnzip(VFSLeaf zipLeaf, VFSContainer targetDir, Identity identity, Roles isAdmin) {
    List<String> lockedFiles = new ArrayList<String>();
    InputStream in = zipLeaf.getInputStream();
    ZipInputStream oZip = new ZipInputStream(in);
    VFSLockManager vfsLockManager = CoreSpringFactory.getImpl(VFSLockManager.class);
    try {
        // unzip files
        ZipEntry oEntr = oZip.getNextEntry();
        while (oEntr != null) {
            if (oEntr.getName() != null && !oEntr.getName().startsWith(DIR_NAME__MACOSX)) {
                if (oEntr.isDirectory()) {
                    // skip MacOSX specific metadata directory
                    // directories aren't locked
                    oZip.closeEntry();
                    oEntr = oZip.getNextEntry();
                    continue;
                } else {
                    // search file
                    VFSContainer createIn = targetDir;
                    String name = oEntr.getName();
                    // check if entry has directories which did not show up as
                    // directories above
                    int dirSepIndex = name.lastIndexOf('/');
                    if (dirSepIndex == -1) {
                        // try it windows style, backslash is also valid format
                        dirSepIndex = name.lastIndexOf('\\');
                    }
                    if (dirSepIndex > 0) {
                        // get subdirs
                        createIn = getAllSubdirs(targetDir, name.substring(0, dirSepIndex), identity, false);
                        if (createIn == null) {
                            // sub directories don't exist, and aren't locked
                            oZip.closeEntry();
                            oEntr = oZip.getNextEntry();
                            continue;
                        }
                        name = name.substring(dirSepIndex + 1);
                    }
                    VFSLeaf newEntry = (VFSLeaf) createIn.resolve(name);
                    if (vfsLockManager.isLockedForMe(newEntry, identity, isAdmin)) {
                        lockedFiles.add(name);
                    }
                }
            }
            oZip.closeEntry();
            oEntr = oZip.getNextEntry();
        }
    } catch (IOException e) {
        return null;
    } finally {
        FileUtils.closeSafely(oZip);
        FileUtils.closeSafely(in);
    }
    return lockedFiles;
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) ZipInputStream(java.util.zip.ZipInputStream) BufferedInputStream(java.io.BufferedInputStream) ZipInputStream(java.util.zip.ZipInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ZipEntry(java.util.zip.ZipEntry) VFSContainer(org.olat.core.util.vfs.VFSContainer) ArrayList(java.util.ArrayList) IOException(java.io.IOException) VFSLockManager(org.olat.core.util.vfs.VFSLockManager)

Aggregations

BufferedInputStream (java.io.BufferedInputStream)4 FileInputStream (java.io.FileInputStream)4 IOException (java.io.IOException)4 InputStream (java.io.InputStream)4 ArrayList (java.util.ArrayList)4 ZipInputStream (java.util.zip.ZipInputStream)4 VFSContainer (org.olat.core.util.vfs.VFSContainer)4 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)4 VFSLockManager (org.olat.core.util.vfs.VFSLockManager)4 ZipEntry (java.util.zip.ZipEntry)2