New API: rm-f: remove a file, ignoring errors if it doesn't exist.

This commit is contained in:
Richard W.M. Jones
2012-09-17 16:25:53 +01:00
parent 74283d58cf
commit a2dc3dbad0
3 changed files with 46 additions and 1 deletions

View File

@@ -106,6 +106,24 @@ do_rm (const char *path)
return 0;
}
int
do_rm_f (const char *path)
{
int r;
CHROOT_IN;
r = unlink (path);
CHROOT_OUT;
/* Ignore ENOENT. */
if (r == -1 && errno != ENOENT) {
reply_with_perror ("%s", path);
return -1;
}
return 0;
}
int
do_chmod (int mode, const char *path)
{

View File

@@ -9802,6 +9802,33 @@ the resulting filesystem may be inconsistent or corrupt.
The returned status indicates whether filesystem corruption was
detected (returns C<1>) or was not detected (returns C<0>)." };
{ defaults with
name = "rm_f";
style = RErr, [Pathname "path"], [];
proc_nr = Some 367;
tests = [
InitScratchFS, Always, TestOutputFalse
[["mkdir"; "/rm_f"];
["touch"; "/rm_f/foo"];
["rm_f"; "/rm_f/foo"];
["rm_f"; "/rm_f/not_exists"];
["exists"; "/rm_f/foo"]];
InitScratchFS, Always, TestLastFail
[["mkdir"; "/rm_f2"];
["mkdir"; "/rm_f2/foo"];
["rm_f"; "/rm_f2/foo"]]
];
shortdesc = "remove a file ignoring errors";
longdesc = "\
Remove the file C<path>.
If the file doesn't exist, that error is ignored. (Other errors,
eg. I/O errors or bad paths, are not ignored)
This call cannot remove directories.
Use C<guestfs_rmdir> to remove an empty directory,
or C<guestfs_rm_rf> to remove directories recursively." };
]
(* Non-API meta-commands available only in guestfish.

View File

@@ -1 +1 @@
366
367