capistrano/capistrano — pull request #290 by kyagi (2012-10-24 06:21:12+00:00)
Title: Enable to return the correctly sorted array for deploy:cleanup if each r...

...elease directory has the same timestamp.

deploy:cleanup removes the latest release directory when each directory has the same timestamp due to the wrong sort order. This patch enables to return the correctly sorted array for deploy:cleanup in that case.

Enable to return the correctly sorted array for deploy:cleanup if each release directory has the same timestamp.
==========

In case each release directory has a same timestamp:
----------

$ ls -l /mnt/myappViaRsync/releases/
total 20
drwxr-xr-x 10 myapp users 4096 Oct 19 02:17 20121023092521
drwxr-xr-x 10 myapp users 4096 Oct 19 02:17 20121023095849
drwxr-xr-x 10 myapp users 4096 Oct 19 02:17 20121023103141
drwxr-xr-x 10 myapp users 4096 Oct 19 02:17 20121024023328
drwxr-xr-x 10 myapp users 4096 Oct 19 02:17 20121024031220

### (NG) the current version returns wrongly sorted array to be removed. ###

$ ruby -e 'local_releases = `ls -xt /mnt/myappViaRsync/releases`.split.reverse; p local_releases;'
["20121024031220", "20121024023328", "20121023103141", "20121023095849", "20121023092521"]

### (OK) this patch enables to return correctly sorted array to be removed. ###

$ ruby -e 'local_releases = `ls /mnt/myappViaRsync/releases | sort -d -n -r | xargs`.split.reverse; p local_releases;'
["20121023092521", "20121023095849", "20121023103141", "20121024023328", "20121024031220"]

In case each release directory has a different timestamp:
----------

$ ls -l /mnt/myappViaCopy/releases/
total 24
drwxr-xr-x 8 myapp users 4096 Sep 27 11:17 20120927021555
drwxr-xr-x 8 myapp users 4096 Oct 11 11:30 20121011023013
drwxr-xr-x 8 myapp users 4096 Oct 12 11:06 20121012020614
drwxr-xr-x 8 myapp users 4096 Oct 12 14:33 20121012053317
drwxr-xr-x 8 myapp users 4096 Oct 18 11:13 20121018021255
drwxr-xr-x 8 myapp users 4096 Oct 23 12:09 20121023030916

### (OK) the current version returns correctly sorted array to be removed. ###

$ ruby -e 'local_releases = `ls -xt /mnt/myappViaCopy/releases`.split.reverse; p local_releases;'
["20120927021555", "20121011023013", "20121012020614", "20121012053317", "20121018021255", "20121023030916"]

### (OK) this patch also returns correctly sorted array to be removed. ###

$ ruby -e 'local_releases = `ls /mnt/myappViaCopy/releases | sort -d -n -r | xargs`.split.reverse; p local_releases;'
["20120927021555", "20121011023013", "20121012020614", "20121012053317", "20121018021255", "20121023030916"]

EOF