mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-21 22:53:37 +00:00
New API: rm-f: remove a file, ignoring errors if it doesn't exist.
This commit is contained in:
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -1 +1 @@
|
||||
366
|
||||
367
|
||||
|
||||
Reference in New Issue
Block a user