diff --git a/core/src/main/java/hudson/FilePath.java b/core/src/main/java/hudson/FilePath.java index 12382c6661cf7eb1d2bbbee08bcda0195654544a..d5028c4b34b5c9fbd5a3dd9aadb36fe888565389 100644 --- a/core/src/main/java/hudson/FilePath.java +++ b/core/src/main/java/hudson/FilePath.java @@ -215,19 +215,21 @@ public final class FilePath implements Serializable { } private void scan(File f, ZipOutputStream zip, String path) throws IOException { - if(f.isDirectory()) { - zip.putNextEntry(new ZipEntry(path+f.getName()+'/')); - zip.closeEntry(); - for( File child : f.listFiles() ) - scan(child,zip,path+f.getName()+'/'); - } else { - zip.putNextEntry(new ZipEntry(path+f.getName())); - FileInputStream in = new FileInputStream(f); - int len; - while((len=in.read(buf))>0) - zip.write(buf,0,len); - in.close(); - zip.closeEntry(); + if (f.canRead()) { + if(f.isDirectory()) { + zip.putNextEntry(new ZipEntry(path+f.getName()+'/')); + zip.closeEntry(); + for( File child : f.listFiles() ) + scan(child,zip,path+f.getName()+'/'); + } else { + zip.putNextEntry(new ZipEntry(path+f.getName())); + FileInputStream in = new FileInputStream(f); + int len; + while((len=in.read(buf))>0) + zip.write(buf,0,len); + in.close(); + zip.closeEntry(); + } } } @@ -258,13 +260,16 @@ public final class FilePath implements Serializable { ZipOutputStream zip = new ZipOutputStream(out); zip.setEncoding(System.getProperty("file.encoding")); for( String entry : glob(dir,glob) ) { - zip.putNextEntry(new ZipEntry(dir.getName()+'/'+entry)); - FileInputStream in = new FileInputStream(new File(dir,entry)); - int len; - while((len=in.read(buf))>0) - zip.write(buf,0,len); - in.close(); - zip.closeEntry(); + File file = new File(dir,entry); + if (file.canRead()) { + zip.putNextEntry(new ZipEntry(dir.getName()+'/'+entry)); + FileInputStream in = new FileInputStream(file); + int len; + while((len=in.read(buf))>0) + zip.write(buf,0,len); + in.close(); + zip.closeEntry(); + } } zip.close(); diff --git a/core/src/main/java/hudson/model/DirectoryBrowserSupport.java b/core/src/main/java/hudson/model/DirectoryBrowserSupport.java index 4daac014b625d0dad72e2eb8d0a093517348348e..7fa307bdbac93ff3deb62a106cb48f5dcb8a504d 100644 --- a/core/src/main/java/hudson/model/DirectoryBrowserSupport.java +++ b/core/src/main/java/hudson/model/DirectoryBrowserSupport.java @@ -229,7 +229,7 @@ public final class DirectoryBrowserSupport { int current=1; while(tokens.hasMoreTokens()) { String token = tokens.nextToken(); - r.add(new Path(createBackRef(total-current+restSize),token,true,0)); + r.add(new Path(createBackRef(total-current+restSize),token,true,0, true)); current++; } return r; @@ -262,17 +262,27 @@ public final class DirectoryBrowserSupport { * File size, or null if this is not a file. */ private final long size; + + /** + * If the current user can read the file. + */ + private final boolean isReadable; - public Path(String href, String title, boolean isFolder, long size) { + public Path(String href, String title, boolean isFolder, long size, boolean isReadable) { this.href = href; this.title = title; this.isFolder = isFolder; this.size = size; + this.isReadable = isReadable; } public boolean isFolder() { return isFolder; } + + public boolean isReadable() { + return isReadable; + } public String getHref() { return href; @@ -283,7 +293,10 @@ public final class DirectoryBrowserSupport { } public String getIconName() { - return isFolder?"folder.gif":"text.gif"; + if (isReadable) + return isFolder?"folder.gif":"text.gif"; + else + return isFolder?"folder-error.gif":"text-error.gif"; } public long getSize() { @@ -320,31 +333,33 @@ public final class DirectoryBrowserSupport { List> r = new ArrayList>(); File[] files = cur.listFiles(); - Arrays.sort(files,new FileComparator()); - - for( File f : files ) { - Path p = new Path(f.getName(),f.getName(),f.isDirectory(),f.length()); - if(!f.isDirectory()) { - r.add(Collections.singletonList(p)); - } else { - // find all empty intermediate directory - List l = new ArrayList(); - l.add(p); - String relPath = f.getName(); - while(true) { - // files that don't start with '.' qualify for 'meaningful files', nor SCM related files - File[] sub = f.listFiles(new FilenameFilter() { - public boolean accept(File dir, String name) { - return !name.startsWith(".") && !name.equals("CVS") && !name.equals(".svn"); - } - }); - if(sub.length!=1 || !sub[0].isDirectory()) - break; - f = sub[0]; - relPath += '/'+f.getName(); - l.add(new Path(relPath,f.getName(),true,0)); + if (files != null) { + Arrays.sort(files,new FileComparator()); + + for( File f : files ) { + Path p = new Path(f.getName(),f.getName(),f.isDirectory(),f.length(), f.canRead()); + if(!f.isDirectory()) { + r.add(Collections.singletonList(p)); + } else { + // find all empty intermediate directory + List l = new ArrayList(); + l.add(p); + String relPath = f.getName(); + while(true) { + // files that don't start with '.' qualify for 'meaningful files', nor SCM related files + File[] sub = f.listFiles(new FilenameFilter() { + public boolean accept(File dir, String name) { + return !name.startsWith(".") && !name.equals("CVS") && !name.equals(".svn"); + } + }); + if(sub==null || sub.length!=1 || !sub[0].isDirectory()) + break; + f = sub[0]; + relPath += '/'+f.getName(); + l.add(new Path(relPath,f.getName(),true,0, f.canRead())); + } + r.add(l); } - r.add(l); } } @@ -412,7 +427,7 @@ public final class DirectoryBrowserSupport { href.append("/"); } - Path path = new Path(href.toString(), filePath.getName(), filePath.isDirectory(), filePath.length()); + Path path = new Path(href.toString(), filePath.getName(), filePath.isDirectory(), filePath.length(), filePath.canRead()); pathList.add(path); } diff --git a/core/src/main/resources/hudson/model/DirectoryBrowserSupport/dir.jelly b/core/src/main/resources/hudson/model/DirectoryBrowserSupport/dir.jelly index 009a4a299e339e2ebe77fd090ca9bbe53424256f..22e224189a743d33c90f681450845a06fc010793 100644 --- a/core/src/main/resources/hudson/model/DirectoryBrowserSupport/dir.jelly +++ b/core/src/main/resources/hudson/model/DirectoryBrowserSupport/dir.jelly @@ -31,18 +31,31 @@ - ${t.title} + + + + ${t.title} + + + ${t.title} + + + / ${x.getSize()} - - fingerprint - - - view + + + + + fingerprint + + + view +