From: Richard Jones Date: Thu, 9 Sep 2010 21:20:28 +0000 (+0100) Subject: daemon: Move 'exists', 'is-file' and 'is-dir' to separate file. X-Git-Tag: 1.5.10~4 X-Git-Url: http://git.annexia.org/?a=commitdiff_plain;h=3a99114360636806078bbf614c241e89661bcc7f;p=libguestfs.git daemon: Move 'exists', 'is-file' and 'is-dir' to separate file. This commit is just code movement. --- diff --git a/daemon/Makefile.am b/daemon/Makefile.am index 0c8be08..dc58134 100644 --- a/daemon/Makefile.am +++ b/daemon/Makefile.am @@ -97,6 +97,7 @@ guestfsd_SOURCES = \ htonl.c \ initrd.c \ inotify.c \ + is.c \ link.c \ ls.c \ luks.c \ diff --git a/daemon/dir.c b/daemon/dir.c index 3a4647c..bc54d51 100644 --- a/daemon/dir.c +++ b/daemon/dir.c @@ -190,28 +190,6 @@ do_mkdir_p (const char *path) return 0; } -int -do_is_dir (const char *path) -{ - int r; - struct stat buf; - - CHROOT_IN; - r = lstat (path, &buf); - CHROOT_OUT; - - if (r == -1) { - if (errno != ENOENT && errno != ENOTDIR) { - reply_with_perror ("stat: %s", path); - return -1; - } - else - return 0; /* Not a directory. */ - } - - return S_ISDIR (buf.st_mode); -} - char * do_mkdtemp (const char *template) { diff --git a/daemon/file.c b/daemon/file.c index da899b6..476f445 100644 --- a/daemon/file.c +++ b/daemon/file.c @@ -270,40 +270,6 @@ do_lchown (int owner, int group, const char *path) } int -do_exists (const char *path) -{ - int r; - - CHROOT_IN; - r = access (path, F_OK); - CHROOT_OUT; - - return r == 0; -} - -int -do_is_file (const char *path) -{ - int r; - struct stat buf; - - CHROOT_IN; - r = lstat (path, &buf); - CHROOT_OUT; - - if (r == -1) { - if (errno != ENOENT && errno != ENOTDIR) { - reply_with_perror ("stat: %s", path); - return -1; - } - else - return 0; /* Not a file. */ - } - - return S_ISREG (buf.st_mode); -} - -int do_write_file (const char *path, const char *content, int size) { int fd; diff --git a/daemon/is.c b/daemon/is.c new file mode 100644 index 0000000..a16596b --- /dev/null +++ b/daemon/is.c @@ -0,0 +1,86 @@ +/* libguestfs - the guestfsd daemon + * Copyright (C) 2010 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., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include + +#include +#include +#include +#include +#include +#include + +#include "../src/guestfs_protocol.h" +#include "daemon.h" +#include "actions.h" + +int +do_exists (const char *path) +{ + int r; + + CHROOT_IN; + r = access (path, F_OK); + CHROOT_OUT; + + return r == 0; +} + +int +do_is_file (const char *path) +{ + int r; + struct stat buf; + + CHROOT_IN; + r = lstat (path, &buf); + CHROOT_OUT; + + if (r == -1) { + if (errno != ENOENT && errno != ENOTDIR) { + reply_with_perror ("stat: %s", path); + return -1; + } + else + return 0; /* Not a file. */ + } + + return S_ISREG (buf.st_mode); +} + +int +do_is_dir (const char *path) +{ + int r; + struct stat buf; + + CHROOT_IN; + r = lstat (path, &buf); + CHROOT_OUT; + + if (r == -1) { + if (errno != ENOENT && errno != ENOTDIR) { + reply_with_perror ("stat: %s", path); + return -1; + } + else + return 0; /* Not a directory. */ + } + + return S_ISDIR (buf.st_mode); +} diff --git a/po/POTFILES.in b/po/POTFILES.in index 8eab9f1..f591374 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -32,6 +32,7 @@ daemon/hexdump.c daemon/htonl.c daemon/initrd.c daemon/inotify.c +daemon/is.c daemon/link.c daemon/ls.c daemon/luks.c