Search in sources :

Example 6 with FileInfo

use of com.intellij.openapi.util.io.win32.FileInfo in project cloudstack by apache.

the class DatastoreMO method fileExists.

public boolean fileExists(String fileFullPath) throws Exception {
    DatastoreFile file = new DatastoreFile(fileFullPath);
    DatastoreFile dirFile = new DatastoreFile(file.getDatastoreName(), file.getDir());
    HostDatastoreBrowserMO browserMo = getHostDatastoreBrowserMO();
    s_logger.info("Search file " + file.getFileName() + " on " + dirFile.getPath());
    HostDatastoreBrowserSearchResults results = browserMo.searchDatastore(dirFile.getPath(), file.getFileName(), true);
    if (results != null) {
        List<FileInfo> info = results.getFile();
        if (info != null && info.size() > 0) {
            s_logger.info("File " + fileFullPath + " exists on datastore");
            return true;
        }
    }
    s_logger.info("File " + fileFullPath + " does not exist on datastore");
    return false;
}
Also used : HostDatastoreBrowserSearchResults(com.vmware.vim25.HostDatastoreBrowserSearchResults) FileInfo(com.vmware.vim25.FileInfo)

Example 7 with FileInfo

use of com.intellij.openapi.util.io.win32.FileInfo in project intellij-community by JetBrains.

the class Win32FsCache method getAttributes.

@Nullable
FileAttributes getAttributes(@NotNull VirtualFile file) {
    VirtualFile parent = file.getParent();
    int parentId = parent instanceof VirtualFileWithId ? ((VirtualFileWithId) parent).getId() : -((VirtualFileWithId) file).getId();
    TIntObjectHashMap<THashMap<String, FileAttributes>> map = getMap();
    THashMap<String, FileAttributes> nestedMap = map.get(parentId);
    String name = file.getName();
    FileAttributes attributes = nestedMap != null ? nestedMap.get(name) : null;
    if (attributes == null) {
        if (nestedMap != null && !(nestedMap instanceof IncompleteChildrenMap)) {
            // our info from parent doesn't mention the child in this refresh session
            return null;
        }
        FileInfo info = myKernel.getInfo(file.getPath());
        if (info == null) {
            return null;
        }
        attributes = info.toFileAttributes();
        if (nestedMap == null) {
            nestedMap = new IncompleteChildrenMap<>(FileUtil.PATH_HASHING_STRATEGY);
            map.put(parentId, nestedMap);
        }
        nestedMap.put(name, attributes);
    }
    return attributes;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) THashMap(gnu.trove.THashMap) FileInfo(com.intellij.openapi.util.io.win32.FileInfo) VirtualFileWithId(com.intellij.openapi.vfs.VirtualFileWithId) FileAttributes(com.intellij.openapi.util.io.FileAttributes) Nullable(org.jetbrains.annotations.Nullable)

Example 8 with FileInfo

use of com.intellij.openapi.util.io.win32.FileInfo in project intellij-community by JetBrains.

the class Win32FsCache method list.

@NotNull
String[] list(@NotNull VirtualFile file) {
    String path = file.getPath();
    FileInfo[] fileInfo = myKernel.listChildren(path);
    if (fileInfo == null || fileInfo.length == 0) {
        return ArrayUtil.EMPTY_STRING_ARRAY;
    }
    String[] names = new String[fileInfo.length];
    TIntObjectHashMap<THashMap<String, FileAttributes>> map = getMap();
    int parentId = ((VirtualFileWithId) file).getId();
    THashMap<String, FileAttributes> nestedMap = map.get(parentId);
    if (nestedMap == null) {
        nestedMap = new THashMap<>(fileInfo.length, FileUtil.PATH_HASHING_STRATEGY);
        map.put(parentId, nestedMap);
    }
    for (int i = 0, length = fileInfo.length; i < length; i++) {
        FileInfo info = fileInfo[i];
        String name = info.getName();
        nestedMap.put(name, info.toFileAttributes());
        names[i] = name;
    }
    return names;
}
Also used : FileInfo(com.intellij.openapi.util.io.win32.FileInfo) THashMap(gnu.trove.THashMap) VirtualFileWithId(com.intellij.openapi.vfs.VirtualFileWithId) FileAttributes(com.intellij.openapi.util.io.FileAttributes) NotNull(org.jetbrains.annotations.NotNull)

Example 9 with FileInfo

use of com.intellij.openapi.util.io.win32.FileInfo in project intellij-community by JetBrains.

the class FileAttributesReadingTest method getAttributes.

@NotNull
private static FileAttributes getAttributes(@NotNull final File file, final boolean checkList) {
    final FileAttributes attributes = FileSystemUtil.getAttributes(file);
    assertNotNull(attributes);
    if (SystemInfo.isWindows && checkList) {
        final String parent = file.getParent();
        if (parent != null) {
            final FileInfo[] infos = IdeaWin32.getInstance().listChildren(parent);
            assertNotNull(infos);
            for (FileInfo info : infos) {
                if (file.getName().equals(info.getName())) {
                    assertEquals(attributes, info.toFileAttributes());
                    return attributes;
                }
            }
            fail(file + " not listed");
        }
    }
    return attributes;
}
Also used : FileInfo(com.intellij.openapi.util.io.win32.FileInfo) NotNull(org.jetbrains.annotations.NotNull)

Example 10 with FileInfo

use of com.intellij.openapi.util.io.win32.FileInfo in project cloudstack by apache.

the class DatastoreMO method folderExists.

public boolean folderExists(String folderParentDatastorePath, String folderName) throws Exception {
    HostDatastoreBrowserMO browserMo = getHostDatastoreBrowserMO();
    HostDatastoreBrowserSearchResults results = browserMo.searchDatastore(folderParentDatastorePath, folderName, true);
    if (results != null) {
        List<FileInfo> info = results.getFile();
        if (info != null && info.size() > 0) {
            s_logger.info("Folder " + folderName + " exists on datastore");
            return true;
        }
    }
    s_logger.info("Folder " + folderName + " does not exist on datastore");
    return false;
}
Also used : HostDatastoreBrowserSearchResults(com.vmware.vim25.HostDatastoreBrowserSearchResults) FileInfo(com.vmware.vim25.FileInfo)

Aggregations

FileInfo (com.vmware.vim25.FileInfo)8 HostDatastoreBrowserSearchResults (com.vmware.vim25.HostDatastoreBrowserSearchResults)8 FileInfo (com.intellij.openapi.util.io.win32.FileInfo)4 FileAttributes (com.intellij.openapi.util.io.FileAttributes)2 VirtualFileWithId (com.intellij.openapi.vfs.VirtualFileWithId)2 FileQueryFlags (com.vmware.vim25.FileQueryFlags)2 HostDatastoreBrowserSearchSpec (com.vmware.vim25.HostDatastoreBrowserSearchSpec)2 THashMap (gnu.trove.THashMap)2 NotNull (org.jetbrains.annotations.NotNull)2 CloudException (com.cloud.exception.CloudException)1 DatastoreFile (com.cloud.hypervisor.vmware.mo.DatastoreFile)1 DatastoreMO (com.cloud.hypervisor.vmware.mo.DatastoreMO)1 HostDatastoreBrowserMO (com.cloud.hypervisor.vmware.mo.HostDatastoreBrowserMO)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 Nullable (org.jetbrains.annotations.Nullable)1 Before (org.junit.Before)1