Added options -x and -X to the "cp" command, used to specify exclude

patterns for file respectively path names.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24585 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold 2008-03-26 04:06:49 +00:00
parent b71cab0178
commit baba54f94f

View File

@ -13,6 +13,7 @@
#include <unistd.h> #include <unistd.h>
#include <AutoDeleter.h> #include <AutoDeleter.h>
#include <EntryFilter.h>
#include <fs_attr.h> #include <fs_attr.h>
#include <StorageDefs.h> #include <StorageDefs.h>
@ -29,6 +30,9 @@
#include "syscalls.h" #include "syscalls.h"
using BPrivate::EntryFilter;
namespace FSShell { namespace FSShell {
@ -37,7 +41,8 @@ static const int sCopyBufferSize = 64 * 1024; // 64 KB
struct Options { struct Options {
Options() Options()
: attributesOnly(false), : entryFilter(),
attributesOnly(false),
ignoreAttributes(false), ignoreAttributes(false),
dereference(true), dereference(true),
force(false), force(false),
@ -45,11 +50,12 @@ struct Options {
{ {
} }
bool attributesOnly; EntryFilter entryFilter;
bool ignoreAttributes; bool attributesOnly;
bool dereference; bool ignoreAttributes;
bool force; bool dereference;
bool recursive; bool force;
bool recursive;
}; };
class Directory; class Directory;
@ -1064,6 +1070,10 @@ copy_entry(FSDomain *sourceDomain, const char *source,
FSDomain *targetDomain, const char *target, const Options &options, FSDomain *targetDomain, const char *target, const Options &options,
bool dereference) bool dereference)
{ {
// apply entry filter
if (!options.entryFilter.Filter(source))
return FSSH_B_OK;
// open the source node // open the source node
Node *sourceNode; Node *sourceNode;
fssh_status_t error = sourceDomain->Open(source, fssh_status_t error = sourceDomain->Open(source,
@ -1253,6 +1263,24 @@ command_cp(int argc, const char* const* argv)
case 'r': case 'r':
options.recursive = true; options.recursive = true;
break; break;
case 'x':
case 'X':
{
const char* pattern;
if (arg[i + 1] == '\0') {
if (++argi >= argc) {
fprintf(stderr, "Error: Option '-%c' need "
"a pattern as parameter\n", arg[i]);
return FSSH_EINVAL;
}
pattern = argv[argi];
} else
pattern = arg + i + 1;
options.entryFilter.AddExcludeFilter(pattern,
arg[i] == 'x');
break;
}
default: default:
fprintf(stderr, "Error: Unknown option '-%c'\n", fprintf(stderr, "Error: Unknown option '-%c'\n",
arg[i]); arg[i]);