Search in sources :

Example 11 with AbstractFile

use of com.mucommander.commons.file.AbstractFile in project mucommander by mucommander.

the class CompareFoldersAction method performAction.

@Override
public void performAction() {
    FileTable leftTable = mainFrame.getLeftPanel().getFileTable();
    FileTable rightTable = mainFrame.getRightPanel().getFileTable();
    FileTableModel leftTableModel = leftTable.getFileTableModel();
    FileTableModel rightTableModel = rightTable.getFileTableModel();
    int nbFilesLeft = leftTableModel.getFileCount();
    int nbFilesRight = rightTableModel.getFileCount();
    int fileIndex;
    String tempFileName;
    AbstractFile tempFile;
    for (int i = 0; i < nbFilesLeft; i++) {
        tempFile = leftTableModel.getFileAt(i);
        if (tempFile.isDirectory())
            continue;
        tempFileName = tempFile.getName();
        fileIndex = -1;
        for (int j = 0; j < nbFilesRight; j++) if (rightTableModel.getFileAt(j).getName().equals(tempFileName)) {
            fileIndex = j;
            break;
        }
        if (fileIndex == -1 || rightTableModel.getFileAt(fileIndex).getDate() < tempFile.getDate()) {
            leftTableModel.setFileMarked(tempFile, true);
            leftTable.repaint();
        }
    }
    for (int i = 0; i < nbFilesRight; i++) {
        tempFile = rightTableModel.getFileAt(i);
        if (tempFile.isDirectory())
            continue;
        tempFileName = tempFile.getName();
        fileIndex = -1;
        for (int j = 0; j < nbFilesLeft; j++) if (leftTableModel.getFileAt(j).getName().equals(tempFileName)) {
            fileIndex = j;
            break;
        }
        if (fileIndex == -1 || leftTableModel.getFileAt(fileIndex).getDate() < tempFile.getDate()) {
            rightTableModel.setFileMarked(tempFile, true);
            rightTable.repaint();
        }
    }
    // Notify registered listeners that currently marked files have changed on the file tables
    leftTable.fireMarkedFilesChangedEvent();
    rightTable.fireMarkedFilesChangedEvent();
}
Also used : FileTableModel(com.mucommander.ui.main.table.FileTableModel) AbstractFile(com.mucommander.commons.file.AbstractFile) FileTable(com.mucommander.ui.main.table.FileTable)

Example 12 with AbstractFile

use of com.mucommander.commons.file.AbstractFile in project mucommander by mucommander.

the class GoToParentInBothPanelsAction method performAction.

// - Action code ---------------------------------------------------------------------
// -----------------------------------------------------------------------------------
/**
 * Opens both the active and inactive folder panel's parent directories.
 */
@Override
public void performAction() {
    Thread openThread;
    AbstractFile parent;
    // If the current panel has a parent file, navigate to it.
    if ((parent = mainFrame.getActivePanel().getCurrentFolder().getParent()) != null) {
        openThread = mainFrame.getActivePanel().tryChangeCurrentFolder(parent);
        // to it.
        if ((parent = mainFrame.getInactivePanel().getCurrentFolder().getParent()) != null) {
            if (openThread != null) {
                while (openThread.isAlive()) {
                    try {
                        openThread.join();
                    } catch (InterruptedException e) {
                    }
                }
            }
            mainFrame.getInactivePanel().tryChangeCurrentFolder(parent);
        }
    }
}
Also used : AbstractFile(com.mucommander.commons.file.AbstractFile)

Example 13 with AbstractFile

use of com.mucommander.commons.file.AbstractFile in project mucommander by mucommander.

the class VSphereFile method ls.

@Override
public AbstractFile[] ls() throws IOException, UnsupportedFileOperationException {
    List<GuestFileInfo> fileInfos = new ArrayList<GuestFileInfo>();
    int index = 0;
    VsphereConnHandler connHandler = null;
    try {
        connHandler = getConnHandler();
        ManagedObjectReference fileManager = getFileManager(connHandler);
        boolean haveRemaining;
        do {
            GuestListFileInfo res = connHandler.getClient().getVimPort().listFilesInGuest(fileManager, vm, credentials, getPathInVm(), index, null, null);
            haveRemaining = (res.getRemaining() != 0);
            fileInfos.addAll(res.getFiles());
            index = fileInfos.size();
        } while (haveRemaining);
        String parentPath = PathUtils.removeTrailingSeparator(fileURL.getPath()) + SEPARATOR;
        Collection<AbstractFile> res = new ArrayList<AbstractFile>();
        for (GuestFileInfo f : fileInfos) {
            final String name = getFileName(f.getPath());
            if (name.equals(".") || name.equals("..")) {
                continue;
            }
            FileURL childURL = (FileURL) fileURL.clone();
            childURL.setPath(parentPath + name);
            AbstractFile newFile = new VSphereFile(childURL, this, f);
            res.add(newFile);
        }
        return res.toArray(new AbstractFile[0]);
    } catch (FileFaultFaultMsg e) {
        translateandLogException(e);
    } catch (GuestOperationsFaultFaultMsg e) {
        translateandLogException(e);
    } catch (InvalidStateFaultMsg e) {
        translateandLogException(e);
    } catch (RuntimeFaultFaultMsg e) {
        translateandLogException(e);
    } catch (TaskInProgressFaultMsg e) {
        translateandLogException(e);
    } catch (InvalidPropertyFaultMsg e) {
        translateandLogException(e);
    } catch (URISyntaxException e) {
        translateandLogException(e);
    } finally {
        releaseConnHandler(connHandler);
    }
    // we never get here..
    return null;
}
Also used : GuestListFileInfo(com.vmware.vim25.GuestListFileInfo) GuestFileInfo(com.vmware.vim25.GuestFileInfo) AbstractFile(com.mucommander.commons.file.AbstractFile) TaskInProgressFaultMsg(com.vmware.vim25.TaskInProgressFaultMsg) ArrayList(java.util.ArrayList) RuntimeFaultFaultMsg(com.vmware.vim25.RuntimeFaultFaultMsg) URISyntaxException(java.net.URISyntaxException) FileURL(com.mucommander.commons.file.FileURL) InvalidStateFaultMsg(com.vmware.vim25.InvalidStateFaultMsg) InvalidPropertyFaultMsg(com.vmware.vim25.InvalidPropertyFaultMsg) FileFaultFaultMsg(com.vmware.vim25.FileFaultFaultMsg) GuestOperationsFaultFaultMsg(com.vmware.vim25.GuestOperationsFaultFaultMsg) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 14 with AbstractFile

use of com.mucommander.commons.file.AbstractFile in project mucommander by mucommander.

the class S3File method listObjects.

protected AbstractFile[] listObjects(String bucketName, String prefix, S3File parent) throws IOException {
    try {
        StorageObjectsChunk chunk = service.listObjectsChunked(bucketName, prefix, "/", Constants.DEFAULT_OBJECT_LIST_CHUNK_SIZE, null, true);
        StorageObject[] objects = chunk.getObjects();
        String[] commonPrefixes = chunk.getCommonPrefixes();
        if (objects.length == 0 && !prefix.equals("")) {
            // This happens only when the directory does not exist
            throw new IOException();
        }
        AbstractFile[] children = new AbstractFile[objects.length + commonPrefixes.length];
        FileURL childURL;
        int i = 0;
        String objectKey;
        for (StorageObject object : objects) {
            // Discard the object corresponding to the prefix itself
            objectKey = object.getKey();
            if (objectKey.equals(prefix))
                continue;
            childURL = (FileURL) fileURL.clone();
            childURL.setPath(bucketName + "/" + objectKey);
            Map<String, Object> parameters = new HashMap<>();
            parameters.put("service", service);
            parameters.put("object", object);
            children[i] = FileFactory.getFile(childURL, parent, parameters);
            i++;
        }
        org.jets3t.service.model.S3Object directoryObject;
        for (String commonPrefix : commonPrefixes) {
            childURL = (FileURL) fileURL.clone();
            childURL.setPath(bucketName + "/" + commonPrefix);
            directoryObject = new org.jets3t.service.model.S3Object(commonPrefix);
            // Common prefixes are not objects per se, and therefore do not have a date, content-length nor owner.
            directoryObject.setLastModifiedDate(new Date(System.currentTimeMillis()));
            directoryObject.setContentLength(0);
            Map<String, Object> parameters = new HashMap<>();
            parameters.put("service", service);
            parameters.put("object", directoryObject);
            children[i] = FileFactory.getFile(childURL, parent, parameters);
            i++;
        }
        // to know in advance whether the prefix will appear in the results or not.
        if (i < children.length) {
            AbstractFile[] childrenTrimmed = new AbstractFile[i];
            System.arraycopy(children, 0, childrenTrimmed, 0, i);
            return childrenTrimmed;
        }
        return children;
    } catch (ServiceException e) {
        throw getIOException(e);
    }
}
Also used : StorageObject(org.jets3t.service.model.StorageObject) AbstractFile(com.mucommander.commons.file.AbstractFile) StorageObjectsChunk(org.jets3t.service.StorageObjectsChunk) HashMap(java.util.HashMap) IOException(java.io.IOException) Date(java.util.Date) FileURL(com.mucommander.commons.file.FileURL) ServiceException(org.jets3t.service.ServiceException) StorageObject(org.jets3t.service.model.StorageObject)

Example 15 with AbstractFile

use of com.mucommander.commons.file.AbstractFile in project mucommander by mucommander.

the class SFTPFile method ls.

@SuppressWarnings("unchecked")
@Override
public AbstractFile[] ls() throws IOException {
    List<LsEntry> files = new ArrayList<LsEntry>();
    try (SFTPConnectionHandler connHandler = (SFTPConnectionHandler) ConnectionPool.getConnectionHandler(connHandlerFactory, fileURL, true)) {
        // Makes sure the connection is started, if not starts it
        connHandler.checkConnection();
        files = connHandler.channelSftp.ls(absPath);
    } catch (Exception e) {
        LOGGER.error("failed to ls %s", getURL());
    }
    int nbFiles = files.size();
    // File doesn't exist, return an empty file array
    if (nbFiles == 0)
        return new AbstractFile[] {};
    AbstractFile[] children = new AbstractFile[nbFiles];
    FileURL childURL;
    String filename;
    int fileCount = 0;
    String parentPath = fileURL.getPath();
    if (!parentPath.endsWith(SEPARATOR))
        parentPath += SEPARATOR;
    // Fill AbstractFile array and discard '.' and '..' files
    for (LsEntry file : files) {
        filename = file.getFilename();
        // Discard '.' and '..' files, dunno why these are returned
        if (filename.equals(".") || filename.equals(".."))
            continue;
        childURL = (FileURL) fileURL.clone();
        childURL.setPath(parentPath + filename);
        children[fileCount++] = FileFactory.getFile(childURL, this, Collections.singletonMap("attributes", new SFTPFileAttributes(childURL, file.getAttrs())));
    }
    // Create new array of the exact file count
    if (fileCount < nbFiles) {
        AbstractFile[] newChildren = new AbstractFile[fileCount];
        System.arraycopy(children, 0, newChildren, 0, fileCount);
        return newChildren;
    }
    return children;
}
Also used : FileURL(com.mucommander.commons.file.FileURL) AbstractFile(com.mucommander.commons.file.AbstractFile) ArrayList(java.util.ArrayList) LsEntry(com.jcraft.jsch.ChannelSftp.LsEntry) SftpException(com.jcraft.jsch.SftpException) IOException(java.io.IOException) UnsupportedFileOperationException(com.mucommander.commons.file.UnsupportedFileOperationException) AuthException(com.mucommander.commons.file.AuthException)

Aggregations

AbstractFile (com.mucommander.commons.file.AbstractFile)150 IOException (java.io.IOException)49 FileURL (com.mucommander.commons.file.FileURL)19 FileSet (com.mucommander.commons.file.util.FileSet)11 FileTable (com.mucommander.ui.main.table.FileTable)11 DialogAction (com.mucommander.ui.dialog.DialogAction)10 File (java.io.File)9 List (java.util.List)8 MainFrame (com.mucommander.ui.main.MainFrame)6 InputStream (java.io.InputStream)6 Vector (java.util.Vector)6 AbstractArchiveEntryFile (com.mucommander.commons.file.archive.AbstractArchiveEntryFile)5 ProtocolFile (com.mucommander.commons.file.protocol.ProtocolFile)5 LocalFile (com.mucommander.commons.file.protocol.local.LocalFile)5 ProgressDialog (com.mucommander.ui.dialog.file.ProgressDialog)5 FolderPanel (com.mucommander.ui.main.FolderPanel)5 FileTableModel (com.mucommander.ui.main.table.FileTableModel)5 Logger (org.slf4j.Logger)5 LoggerFactory (org.slf4j.LoggerFactory)5 UnsupportedFileOperationException (com.mucommander.commons.file.UnsupportedFileOperationException)4