From 159e8f8c3a0e4df5c0a34c1693192a3679a47322 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Mon, 21 Jan 2013 16:58:54 +0000 Subject: [PATCH] New API: rename: Rename file within the same filesystem (RHBZ#895910). --- daemon/Makefile.am | 1 + daemon/rename.c | 41 +++++++++++++++++++++++++++++++++++++++++ generator/actions.ml | 21 ++++++++++++++++++++- po/POTFILES | 1 + src/MAX_PROC_NR | 2 +- 5 files changed, 64 insertions(+), 2 deletions(-) create mode 100644 daemon/rename.c diff --git a/daemon/Makefile.am b/daemon/Makefile.am index a05771ee2..1a1626f19 100644 --- a/daemon/Makefile.am +++ b/daemon/Makefile.am @@ -158,6 +158,7 @@ guestfsd_SOURCES = \ proto.c \ readdir.c \ realpath.c \ + rename.c \ rsync.c \ scrub.c \ selinux.c \ diff --git a/daemon/rename.c b/daemon/rename.c new file mode 100644 index 000000000..d08c1abcf --- /dev/null +++ b/daemon/rename.c @@ -0,0 +1,41 @@ +/* libguestfs - the guestfsd daemon + * Copyright (C) 2013 Red Hat Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include + +#include + +#include "daemon.h" +#include "actions.h" + +int +do_rename (const char *oldpath, const char *newpath) +{ + int r; + + CHROOT_IN; + r = rename (oldpath, newpath); + CHROOT_OUT; + + if (r == -1) { + reply_with_perror ("rename: %s: %s", oldpath, newpath); + return -1; + } + + return 0; +} diff --git a/generator/actions.ml b/generator/actions.ml index d75de8db9..13451a6d1 100644 --- a/generator/actions.ml +++ b/generator/actions.ml @@ -4617,7 +4617,9 @@ recursively using the C command." }; shortdesc = "move a file"; longdesc = "\ This moves a file from C to C where C is -either a destination filename or destination directory." }; +either a destination filename or destination directory. + +See also: C." }; { defaults with name = "drop_caches"; @@ -10679,6 +10681,23 @@ Return the type GUID of numbered GPT partition C. For MBR partitions, return an appropriate GUID corresponding to the MBR type. Behaviour is undefined for other partition types." }; + { defaults with + name = "rename"; + style = RErr, [Pathname "oldpath"; Pathname "newpath"], []; + proc_nr = Some 394; + tests = [ + InitScratchFS, Always, TestOutputFalse ( + [["mkdir"; "/rename"]; + ["write"; "/rename/old"; "file content"]; + ["rename"; "/rename/old"; "/rename/new"]; + ["is_file"; "/rename/old"]]) + ]; + shortdesc = "rename a file on the same filesystem"; + longdesc = "\ +Rename a file to a new place on the same filesystem. This is +the same as the Linux L system call. In most cases +you are better to use C instead." }; + ] (* Non-API meta-commands available only in guestfish. diff --git a/po/POTFILES b/po/POTFILES index 272b62cc9..7ceb59438 100644 --- a/po/POTFILES +++ b/po/POTFILES @@ -73,6 +73,7 @@ daemon/pingdaemon.c daemon/proto.c daemon/readdir.c daemon/realpath.c +daemon/rename.c daemon/rsync.c daemon/scrub.c daemon/selinux.c diff --git a/src/MAX_PROC_NR b/src/MAX_PROC_NR index 25685cf6b..0ca45a091 100644 --- a/src/MAX_PROC_NR +++ b/src/MAX_PROC_NR @@ -1 +1 @@ -393 +394