1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
|
/* guestfish - guest filesystem shell
* Copyright (C) 2010-2023 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.
*/
/**
* This file implements the guestfish commands C<copy-in> and
* C<copy-out>.
*/
#include <config.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <libintl.h>
#include <errno.h>
#include "fish.h"
int
run_copy_in (const char *cmd, size_t argc, char *argv[])
{
CLEANUP_FREE char *remote = NULL;
if (argc < 2) {
fprintf (stderr,
_("use 'copy-in <local> [<local>...] <remotedir>' to copy files into the image\n"));
return -1;
}
/* Remote directory is always the last arg.
* Allow "win:" prefix on remote.
*/
remote = win_prefix (argv[argc-1]);
if (remote == NULL)
return -1;
const int nr_locals = argc-1;
/* Upload each local one at a time using copy-in. */
int i;
for (i = 0; i < nr_locals; ++i) {
int r = guestfs_copy_in (g, argv[i], remote);
if (r == -1)
return -1;
}
return 0;
}
int
run_copy_out (const char *cmd, size_t argc, char *argv[])
{
if (argc < 2) {
fprintf (stderr,
_("use 'copy-out <remote> [<remote>...] <localdir>' to copy files out of the image\n"));
return -1;
}
/* Local directory is always the last arg. */
const char *local = argv[argc-1];
const int nr_remotes = argc-1;
/* Download each remote one at a time using copy-out. */
int i, r;
for (i = 0; i < nr_remotes; ++i) {
CLEANUP_FREE char *remote = NULL;
/* Allow win:... prefix on remotes. */
remote = win_prefix (argv[i]);
if (remote == NULL)
return -1;
r = guestfs_copy_out (g, remote, local);
if (r == -1)
return -1;
}
return 0;
}
|