mirror of
https://github.com/jenkinsci/jenkins.git
synced 2026-11-11 19:16:42 +00:00
[fixed] Workspace link generates NPE when workspace contains files that Hudson can not access (issue #1633)
git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@9065 71c3de6d-444a-0410-be80-ed276b4c234a
This commit is contained in:
1 parent
1332d2d28d
commit
e2871c00a2
3 files changed
+87
-54
No files matched your search
@@ -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();
|
||||
|
||||
@@ -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<List<Path>> r = new ArrayList<List<Path>>();
|
||||
|
||||
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<Path> l = new ArrayList<Path>();
|
||||
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<Path> l = new ArrayList<Path>();
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@@ -31,18 +31,31 @@
|
||||
</td>
|
||||
<td>
|
||||
<j:forEach var="t" items="${f}" varStatus="st">
|
||||
<a href="${t.href}">${t.title}</a>
|
||||
|
||||
<j:choose>
|
||||
<j:when test="${x.readable}">
|
||||
<a href="${t.href}">${t.title}</a>
|
||||
</j:when>
|
||||
<j:otherwise>
|
||||
${t.title}
|
||||
</j:otherwise>
|
||||
</j:choose>
|
||||
|
||||
<j:if test="${!st.last}">/</j:if>
|
||||
</j:forEach>
|
||||
</td>
|
||||
<j:if test="${!x.folder}">
|
||||
<td class="fileSize">
|
||||
${x.getSize()}
|
||||
<a href="${x.href}/*fingerprint*/">
|
||||
<img src="${imagesURL}/16x16/fingerprint.gif" alt="fingerprint" />
|
||||
</a>
|
||||
<st:nbsp/>
|
||||
<a href="${x.href}/*view*/">view</a>
|
||||
</td>
|
||||
<td>
|
||||
<j:if test="${x.readable}">
|
||||
<a href="${x.href}/*fingerprint*/">
|
||||
<img src="${imagesURL}/16x16/fingerprint.gif" alt="fingerprint" />
|
||||
</a>
|
||||
<st:nbsp/>
|
||||
<a href="${x.href}/*view*/">view</a>
|
||||
</j:if>
|
||||
</td>
|
||||
</j:if>
|
||||
</tr>
|
||||
|
||||
Reference in new issue
Block a user