autotest_quickmerge: Preserve file permissions of destination files.

When rsyncing files from the source tree to build tree, preserve file
permissions in the build tree. This way, any permissions set by the initial
emerge will be preserved.
On the other hand, if a new file is created, it will get the least restrictive
file permission allowed in the chroot, making sure all developers get the same
permissions.

Before this CL, the file permissions on files copied by test_that were preserved
from the source tree, and hence were dependent on the umask of developers' host.

BUG=chromium:342967
TEST=(1) Checkout a fresh autotest repo with host umask set to 027. This ensures
         that files in the source tree are not world-readable.
     (2) emerge autotest
     (3) In the autotest repo, edit files/client/cros/cellular/cellular.py
     (4) test_that DUT network_3GModemPresent
     (5) On the DUT, check that /usr/local/autotest/cros/cellular/cellular.py is
         world-readable.

Change-Id: I29bfe75fa5e94c8d21600ae4e1513c7c6457f9a2
Reviewed-on: https://chromium-review.googlesource.com/186019
Tested-by: Prathmesh Prabhu <pprabhu@chromium.org>
Reviewed-by: Aviv Keshet <akeshet@chromium.org>
Commit-Queue: Prathmesh Prabhu <pprabhu@chromium.org>
diff --git a/scripts/autotest_quickmerge.py b/scripts/autotest_quickmerge.py
index 8c0c13c..a6a1fa7 100644
--- a/scripts/autotest_quickmerge.py
+++ b/scripts/autotest_quickmerge.py
@@ -284,6 +284,14 @@
   """
   command = ['rsync', '-a']
 
+  # For existing files, preserve destination permissions. This ensures that
+  # existing files end up with the file permissions set by the ebuilds.
+  # If this script copies over a file that does not exist in the destination
+  # tree, it will set the least restrictive permissions allowed in the
+  # destination tree. This could happen if the file copied is not installed by
+  # *any* ebuild, or if the ebuild that installs the file was never emerged.
+  command += ['--no-p', '--chmod=ugo=rwX']
+
   if pretend:
     command += ['-n']