Skip to content

vfs: urls fail when real file system is not populated #226

@kudrevatykh

Description

@kudrevatykh

Real FS when using jboss-vfs can be populated lazily and reflections can't find any class when it happens
quick & dirty workaround for this case is touch physical files before creating SystemDir

            public Vfs.Dir createDir(URL url) throws Exception {
                Object content = url.openConnection().getContent();
                Class<?> virtualFile = ClasspathHelper.contextClassLoader().loadClass("org.jboss.vfs.VirtualFile");
                java.io.File physicalFile = (java.io.File) virtualFile.getMethod("getPhysicalFile").invoke(content);
                if ((boolean)virtualFile.getMethod("isDirectory").invoke(content)) {
                    for(Object virtFile: (List)virtualFile.getMethod("getChildrenRecursively").invoke(content)) {
                        virtualFile.getMethod("getPhysicalFile").invoke(virtFile);
                    }
                }
                String name = (String) virtualFile.getMethod("getName").invoke(content);
                java.io.File file = new java.io.File(physicalFile.getParentFile(), name);
                if (!file.exists() || !file.canRead()) file = physicalFile;
                return file.isDirectory() ? new SystemDir(file) : new ZipDir(new JarFile(file));
            }

but I'm working now for more clear implementation of Vfs.Dir and Vfs.File with jboss-vfs backend

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions