Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

`CopySpec.eachFile(…)` Action not Applied to Copied Directories #2940

Open
cspurk opened this issue Sep 14, 2017 · 2 comments

Comments

@cspurk
Copy link

commented Sep 14, 2017

Expected Behavior

The action given to CopySpec.eachFile(…) should also be applied to each copied directory – at least when includeEmptyDirs == true.

Current Behavior

The action given to CopySpec.eachFile(…) is only applied to normal files, even if includeEmptyDirs == true.

Context

In shell terms, I would like to do something as simple as cp -r source/*/* target/ (i.e., copy all contents of the subdirectories of source to target – including possibly empty directories). Unfortunately, I couldn’t find any comparably simple way to achieve this in a Gradle Copy task, so I tried to remove the leading subdirectory path segment from each copied file in a CopySpec.eachFile(…) action.

Steps to Reproduce (for bugs)

Try the following bash script to quickly set up and execute a simple sample build:

mkdir test
cd test
mkdir -p source/empty_dir source/path/to/other_empty_dir source/some_dir
touch source/some_dir/file.txt
gradle wrapper --gradle-version 4.1
cat > build.gradle <<'EOF'
task foo(type: Copy) {
    from 'source'
    into 'target'
    includeEmptyDirs = true
    eachFile { println "SEEN: $it" }
}
EOF
./gradlew foo

It prints the following:

> Task :foo
SEEN: file '/tmp/test/source/some_dir/file.txt'


BUILD SUCCESSFUL in 0s
1 actionable task: 1 executed

I would expect to also get “SEEN” lines for at least the empty directories. They are definitely copied:

$ tree target/
target/
├── empty_dir
├── path
│   └── to
│       └── other_empty_dir
└── some_dir
    └── file.txt

5 directories, 1 file

Your Environment

$ ./gradlew -version

------------------------------------------------------------
Gradle 4.1
------------------------------------------------------------

Build time:   2017-08-07 14:38:48 UTC
Revision:     941559e020f6c357ebb08d5c67acdb858a3defc2

Groovy:       2.4.11
Ant:          Apache Ant(TM) version 1.9.6 compiled on June 29 2015
JVM:          1.8.0_131 (Oracle Corporation 25.131-b11)
OS:           Linux 4.4.0-93-generic amd64
@wszeboreq

This comment has been minimized.

Copy link

commented Jan 10, 2019

Maybe, in order to avoid the backward compatibility problems, it would be possible to provide an 'eachFile' method variant with additional parameter like e.g. 'includeDirs', so one may use:

eachFile(includeDirs: true) {
    println "SEEN: $it"
}

We are very interested in having 'eachFile()' variant which works also for directories (lack of it makes it not possible, or at least very hard, to use complete workarounds for the #1108 problem).

@lacasseio

This comment has been minimized.

Copy link
Member

commented Feb 14, 2019

As part of solving this issue, the caution section user guide chapter "Working with files" should be updated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.