1.1 --- a/conf/fsaccess.txt Wed Mar 23 22:58:37 2022 +0100
1.2 +++ b/conf/fsaccess.txt Thu Mar 24 22:11:47 2022 +0100
1.3 @@ -11,3 +11,9 @@
1.4 copy-in rom/fsaccess.txt home/paulb/fsaccess/script.txt
1.5 ls home/paulb/fsaccess
1.6 stat home/paulb/fsaccess/script.txt
1.7 +rm home/paulb/fsaccess/script.txt
1.8 +ls home/paulb/fsaccess
1.9 +rm home/paulb/fsaccess/fsaccess.txt
1.10 +ls home/paulb/fsaccess
1.11 +rmdir home/paulb/fsaccess
1.12 +ls home/paulb
2.1 --- a/fsaccess/Makefile Wed Mar 23 22:58:37 2022 +0100
2.2 +++ b/fsaccess/Makefile Thu Mar 24 22:11:47 2022 +0100
2.3 @@ -7,8 +7,8 @@
2.4
2.5 SRC_C = \
2.6 file.c fsaccess.c input.c session.c ops.c \
2.7 - op_copy_in.c op_list_objects.c op_make_dirs.c op_script.c \
2.8 - op_stat_objects.c
2.9 + op_copy_in.c op_list_objects.c op_make_dirs.c op_remove.c \
2.10 + op_script.c op_stat_objects.c
2.11
2.12 REQUIRES_LIBS = l4re_c-util libfsclient libmem libipc libsystypes libe2access libe2access_blockserver
2.13
3.1 --- a/fsaccess/fsaccess.c Wed Mar 23 22:58:37 2022 +0100
3.2 +++ b/fsaccess/fsaccess.c Thu Mar 24 22:11:47 2022 +0100
3.3 @@ -39,7 +39,6 @@
3.4 Transfer operations:\n\
3.5 \n\
3.6 copy-in Copy files into a directory within the image\n\
3.7 - copy-out Copy files from the image into a directory\n\
3.8 \n\
3.9 Image operations:\n\
3.10 \n\
3.11 @@ -58,15 +57,10 @@
3.12
3.13 struct operation operations[] = {
3.14 {"copy-in", copy_in},
3.15 -#if 0
3.16 - {"copy-out", copy_out},
3.17 -#endif
3.18 {"ls", list_objects},
3.19 {"mkdir", make_dirs},
3.20 -#if 0
3.21 {"rm", remove_non_dirs},
3.22 {"rmdir", remove_dirs},
3.23 -#endif
3.24 {"script", run_script},
3.25 {"stat", stat_objects},
3.26 {NULL, NULL},
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
4.2 +++ b/fsaccess/op_remove.c Thu Mar 24 22:11:47 2022 +0100
4.3 @@ -0,0 +1,102 @@
4.4 +/*
4.5 + * Remove objects from a filesystem.
4.6 + *
4.7 + * Copyright (C) 2019, 2022 Paul Boddie <paul@boddie.org.uk>
4.8 + *
4.9 + * This program is free software; you can redistribute it and/or
4.10 + * modify it under the terms of the GNU General Public License as
4.11 + * published by the Free Software Foundation; either version 2 of
4.12 + * the License, or (at your option) any later version.
4.13 + *
4.14 + * This program is distributed in the hope that it will be useful,
4.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4.17 + * GNU General Public License for more details.
4.18 + *
4.19 + * You should have received a copy of the GNU General Public License
4.20 + * along with this program; if not, write to the Free Software
4.21 + * Foundation, Inc., 51 Franklin Street, Fifth Floor,
4.22 + * Boston, MA 02110-1301, USA
4.23 + */
4.24 +
4.25 +#include <stdio.h>
4.26 +#include <sys/stat.h>
4.27 +
4.28 +#include <fsclient/client.h>
4.29 +
4.30 +#include "ops.h"
4.31 +
4.32 +
4.33 +
4.34 +/* Remove objects from the filesystem image. */
4.35 +
4.36 +static int _remove(int argc, char *argv[], int dir_only)
4.37 +{
4.38 + int i;
4.39 + const char *path;
4.40 + long err;
4.41 + struct stat st;
4.42 +
4.43 + /* Remove each directory with the given pathname. */
4.44 +
4.45 + for (i = 0; i < argc; i++)
4.46 + {
4.47 + path = argv[i];
4.48 +
4.49 + /* Detect missing objects. */
4.50 +
4.51 + err = client_stat(path, &st);
4.52 +
4.53 + if (err)
4.54 + {
4.55 + fprintf(stderr, "Could not stat object: %s\n", path);
4.56 + return 1;
4.57 + }
4.58 +
4.59 + /* Insist on a directory if specified. */
4.60 +
4.61 + if (dir_only)
4.62 + {
4.63 + if (!S_ISDIR(st.st_mode))
4.64 + {
4.65 + fprintf(stderr, "Not a directory: %s\n", path);
4.66 + return 1;
4.67 + }
4.68 + }
4.69 +
4.70 + /* Otherwise, insist on a non-directory. */
4.71 +
4.72 + else if (S_ISDIR(st.st_mode))
4.73 + {
4.74 + fprintf(stderr, "Cannot remove a directory: %s\n", path);
4.75 + return 1;
4.76 + }
4.77 +
4.78 + /* Remove the object. */
4.79 +
4.80 + if (client_remove(path))
4.81 + {
4.82 + fprintf(stderr, "Could not remove object: %s\n", path);
4.83 + return 1;
4.84 + }
4.85 + }
4.86 +
4.87 + return 0;
4.88 +}
4.89 +
4.90 +/* Remove directories from the filesystem image. */
4.91 +
4.92 +int remove_dirs(int argc, char *argv[])
4.93 +{
4.94 + return _remove(argc, argv, 1);
4.95 +}
4.96 +
4.97 +/* Remove non-directories from the filesystem image. */
4.98 +
4.99 +int remove_non_dirs(int argc, char *argv[])
4.100 +{
4.101 + return _remove(argc, argv, 0);
4.102 +}
4.103 +
4.104 +/* vim: tabstop=4 expandtab shiftwidth=4
4.105 +*/