From fd51b44e2db4c242cf6772d6497547a3e8b1e4ae Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Wed, 5 Sep 2007 03:06:04 +0000 Subject: [PATCH] * HostSymLink::fPath wasn't set to NULL by the constructor, which could cause a segfault if Init() failed early. * The -d (don't dereference symlinks) option of cp shall only take effect on the top level. When descending into directories, symlinks shall never be dereferenced. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22179 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/tools/fs_shell/command_cp.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/tools/fs_shell/command_cp.cpp b/src/tools/fs_shell/command_cp.cpp index ff62cb342a..a51341c8cf 100644 --- a/src/tools/fs_shell/command_cp.cpp +++ b/src/tools/fs_shell/command_cp.cpp @@ -300,7 +300,8 @@ class HostSymLink : public SymLink, public HostNode { public: HostSymLink() : SymLink(), - HostNode() + HostNode(), + fPath(NULL) { } @@ -858,7 +859,8 @@ private: // #pragma mark - static fssh_status_t 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); static FSDomain * get_file_domain(const char *target, const char *&fsTarget) @@ -931,7 +933,7 @@ copy_dir_contents(FSDomain *sourceDomain, const char *source, PathDeleter targetDeleter(targetEntry); fssh_status_t error = copy_entry(sourceDomain, sourceEntry, - targetDomain, targetEntry, options); + targetDomain, targetEntry, options, false); if (error != FSSH_B_OK) return error; } @@ -1032,12 +1034,13 @@ copy_attributes(const char *source, Node *sourceNode, const char *target, static fssh_status_t 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) { // open the source node Node *sourceNode; fssh_status_t error = sourceDomain->Open(source, - FSSH_O_RDONLY | (options.dereference ? 0 : FSSH_O_NOTRAVERSE), + FSSH_O_RDONLY | (dereference ? 0 : FSSH_O_NOTRAVERSE), sourceNode); if (error != FSSH_B_OK) { fprintf(stderr, "Error: Failed to open source path `%s': %s\n", source, @@ -1365,7 +1368,7 @@ command_cp(int argc, const char* const* argv) PathDeleter targetDeleter(targetEntry); error = copy_entry(sourceDomain, source, targetDomain, - targetEntry, options); + targetEntry, options, options.dereference); } } else { // 1.2. target is no dir: @@ -1377,7 +1380,7 @@ command_cp(int argc, const char* const* argv) // -> we create the target as a clone of the source // (copy_entry(, )) error = copy_entry(sourceDomain, source, targetDomain, target, - options); + options, options.dereference); } if (error != 0)