提交 d53b476e 编写于 作者: K kohsuke

fixed a problem where Hudson fails to wipe out files in a directory if the...

fixed a problem where Hudson fails to wipe out files in a directory if the directory is not writable.

git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@8724 71c3de6d-444a-0410-be80-ed276b4c234a
上级 fb116b10
......@@ -153,10 +153,36 @@ public class Util {
return;
// perhaps this file is read-only?
makeWritable(f);
/*
on Unix both the file and the directory that contains it has to be writable
for a file deletion to be successful. (Confirmed on Solaris 9)
$ ls -la
total 6
dr-xr-sr-x 2 hudson hudson 512 Apr 18 14:41 .
dr-xr-sr-x 3 hudson hudson 512 Apr 17 19:36 ..
-r--r--r-- 1 hudson hudson 469 Apr 17 19:36 manager.xml
-rw-r--r-- 1 hudson hudson 0 Apr 18 14:41 x
$ rm x
rm: x not removed: Permission denied
*/
makeWritable(f.getParentFile());
if(!f.delete() && f.exists())
throw new IOException("Unable to delete " + f.getPath());
}
}
/**
* Makes the given file writable.
*/
private static void makeWritable(File f) {
// try chmod. this becomes no-op if this is not Unix.
try {
Chmod chmod = new Chmod();
chmod.setProject(new org.apache.tools.ant.Project());
chmod.setProject(new Project());
chmod.setFile(f);
chmod.setPerm("u+w");
chmod.execute();
......@@ -170,10 +196,6 @@ public class Util {
} catch (NoSuchMethodError e) {
// not JDK6
}
if(!f.delete() && f.exists())
throw new IOException("Unable to delete " + f.getPath());
}
}
public static void deleteRecursive(File dir) throws IOException {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册