diff options
author | Richard Jones <rjones@redhat.com> | 2010-09-09 22:20:28 +0100 |
---|---|---|
committer | Richard Jones <rjones@redhat.com> | 2010-09-09 22:45:22 +0100 |
commit | 3a99114360636806078bbf614c241e89661bcc7f (patch) | |
tree | 8247c84a713c4c57144ae337ab52080810a29743 /daemon | |
parent | 55b6e18f95950b1a2ec69d549c9e6c8a5758d166 (diff) | |
download | libguestfs-3a99114360636806078bbf614c241e89661bcc7f.tar.gz libguestfs-3a99114360636806078bbf614c241e89661bcc7f.tar.xz libguestfs-3a99114360636806078bbf614c241e89661bcc7f.zip |
daemon: Move 'exists', 'is-file' and 'is-dir' to separate file.
This commit is just code movement.
Diffstat (limited to 'daemon')
-rw-r--r-- | daemon/Makefile.am | 1 | ||||
-rw-r--r-- | daemon/dir.c | 22 | ||||
-rw-r--r-- | daemon/file.c | 34 | ||||
-rw-r--r-- | daemon/is.c | 86 |
4 files changed, 87 insertions, 56 deletions
diff --git a/daemon/Makefile.am b/daemon/Makefile.am index 0c8be08e..dc581341 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 3a4647cd..bc54d518 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 da899b6c..476f4456 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 00000000..a16596be --- /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 <config.h> + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <sys/types.h> +#include <sys/stat.h> + +#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); +} |