Sync Task - Anyway to preserve a file if it exists in target?


(Julian Hall) #1

I want to sync the contents from an zip archive to a location.

There are certain files that are in the archive that I want to keep in the target if they already exists. Essentially the ‘preserveInTarget’ option that the ant.sync provides.

This example I want to deploy the contents of foo.zip to /tmp/testdestination/ but preserve the file ‘leave.me’ if it exists.

tasks testSync() {
    into( '/tmp/testdestination/' )
     from ( zipTree('foo.zip')) {
        exclude { currFile ->
            ('leave.me' == currFile.name) && (new File(destinationDir,currFile.path).exists())
         }
    }
}

This seems to copy the file on the first invocation. But then seems to delete it on the next, adds it back again on the next after that… and so on. Any help on what I’m trying to accomplish would be greatful.

Julian


(Peter Niederwieser) #2

Gradle’s ‘Sync’ task doesn’t currently support this. The easiest way out is to use the Ant task.


(Julian Hall) #3

Ah thanks, i’ll stop banging my head against my desk now.

One questions though - with the ant.sync - I believe it uses the file time-stamp as a decision on moving the file or not.

From what I noticed the Gradle Sync task uses some sort of hash. Is that correct?


(Peter Niederwieser) #4

The current implementation of the ‘Sync’ task is very simple. It either copies nothing (if the task is up-to-date*) or everything (if the task is not up-to-date). In the latter case, it also deletes everything from the target that wasn’t copied.

(*) Up-to-date checks are a generic feature leveraging both hashing and timestamps.


(Julian Hall) #5

Hi Peter - Just curious how you would get around with without using Ant’s sync?

I was attempting to do it before but ran into issues:

http://stackoverflow.com/questions/6860114/ant-sync-task-with-zipfileset


(Davide Cavestro) #6

Is there any chance to add this feature to the Sync Task? Having something like a

preventDelete ‘myfile.txt’ would come really handy. The semantic would be

  1. check pre-existing files that weren’t copied 2. if they match the “delete prevention” pattern leave them alone 3. otherwise proceed with the deletion