Skip to content

Recursive copy behaviour - nesting the source directory inside the destination #110

@barneda

Description

@barneda

Description

The zopen version of the cp command behaves differently from the standard z/OS /bin/cp when performing recursive copies with a trailing slash on the source directory. The zopen version creates an extra layer of directory structure, nesting the source directory inside the destination, while the standard /bin/cp copies the contents directly into the destination.

Test Setup

Initial directory structure:

/u/myuser/ZOPEN-TST/
├── binCopy/      (empty destination for /bin/cp test)
├── copyFrom/     (source directory)
│   ├── firstFile
│   ├── secondFile
│   ├── firstDir/
│   └── secondDir/
│       └── thirdFile
└── zopenCopy/    (empty destination for zopen cp test)

Reproduction Steps

  1. Test with standard /bin/cp:

    /bin/cp -R copyFrom/ binCopy
  2. Test with zopen cp:

    /u/myuser/zopen/usr/local/altbin/cp -R copyFrom/ zopenCopy

Expected Behavior (Standard /bin/cp)

The contents of copyFrom/ are copied directly into binCopy/:

binCopy/
├── firstFile
├── secondFile
├── firstDir/
└── secondDir/
    └── thirdFile

Verification with ls -l binCopy/*:

-rw-------  1 MYUSER TSOUSER    0 Feb 18 15:53 binCopy/firstFile
-rw-------  1 MYUSER TSOUSER    0 Feb 18 15:53 binCopy/secondFile

binCopy/firstDir:
total 0

binCopy/secondDir:
total 0
-rw-------  1 MYUSER TSOUSER 0 Feb 18 15:53 thirdFile

Actual Behavior (zopen cp)

An extra directory layer is created - the entire copyFrom directory is nested inside zopenCopy/:

zopenCopy/
└── copyFrom/          ← Extra directory layer
    ├── firstFile
    ├── secondFile
    ├── firstDir/
    └── secondDir/
        └── thirdFile

Verification with ls -l zopenCopy/*:

total 4
drwx------  2 MYUSER TSOUSER    0 Feb 18 15:54 firstDir
-rw-------  1 MYUSER TSOUSER    0 Feb 18 15:54 firstFile
drwx------  2 MYUSER TSOUSER 8192 Feb 18 15:54 secondDir
-rw-------  1 MYUSER TSOUSER    0 Feb 18 15:54 secondFile

Note: The ls output shows files and directories at the root of zopenCopy/, but this is misleading - these are actually inside a copyFrom/ subdirectory that was created by the zopen cp command. This demonstrates the key difference: /bin/cp places content directly in the destination, while zopen cp creates an extra directory layer.

Verification with ls -l zopenCopy/:

total 4
drwx------  4 MYUSER TSOUSER 8192 Feb 18 15:54 copyFrom

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions