mirror of
https://github.com/rust-lang/cargo.git
synced 2025-10-04 11:34:35 +00:00
Fix rm_rf on windows
Apparently git checkouts have objects in the database with permissions 444 which need to be changed to something with a write permission before removal.
This commit is contained in:
parent
200398ef8f
commit
06d19011db
@ -33,9 +33,23 @@ impl PathExt for Path {
|
|||||||
*/
|
*/
|
||||||
fn rm_rf(&self) -> IoResult<()> {
|
fn rm_rf(&self) -> IoResult<()> {
|
||||||
if self.exists() {
|
if self.exists() {
|
||||||
fs::rmdir_recursive(self)
|
// On windows, apparently git checks out the database with objects
|
||||||
|
// set to the permission 444, and apparently you can't unlink a file
|
||||||
|
// with permissions 444 because you don't have write permissions.
|
||||||
|
// Whow knew!
|
||||||
|
//
|
||||||
|
// If the rmdir fails due to a permission denied error, then go back
|
||||||
|
// and change everything to have write permissions, then remove
|
||||||
|
// everything.
|
||||||
|
match fs::rmdir_recursive(self) {
|
||||||
|
Err(io::IoError { kind: io::PermissionDenied, .. }) => {}
|
||||||
|
e => return e,
|
||||||
}
|
}
|
||||||
else {
|
for path in try!(fs::walk_dir(self)) {
|
||||||
|
try!(fs::chmod(&path, io::UserRWX));
|
||||||
|
}
|
||||||
|
fs::rmdir_recursive(self)
|
||||||
|
} else {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user