Never overwrite destination paths.

This is the minimum change that lets us skip updating files in place in
the destination bucket. A follow up CL will clean up the logic related
to figuring out if a file has changed so that it can be updated.

BUG=chromium:703244
TEST=$ python
     >> import mirror
     >> mirror.Mirror(
     .. 'gs://chromeos-mirror/gentoo/distfiles/libseccomp-2.3.1.tar.gz',
     .. 'gs://chromeos-mirror/gentoo/distfiles/libseccomp-2.3.1.tar.gz',
     .. lambda x: 'blah'
     .. )

Change-Id: I63622cf9c0c099ea705c895100bcfe9eabf05105
Reviewed-on: https://chromium-review.googlesource.com/483863
Commit-Ready: Prathmesh Prabhu <pprabhu@chromium.org>
Tested-by: Prathmesh Prabhu <pprabhu@chromium.org>
Reviewed-by: Aviv Keshet <akeshet@chromium.org>
diff --git a/bin/mirror.py b/bin/mirror.py
index a8395cf..5d760e9 100644
--- a/bin/mirror.py
+++ b/bin/mirror.py
@@ -135,6 +135,11 @@
     print '%d/%d %0.2f%% - %s' % (
         index, original_count,
         float(index) * 100 / float(original_count), path)
+
+    if _GSPathExists(gsutil, dst):
+      print 'Destination path %s exists, skipped' % dst
+      continue
+
     # Get state stamp.
     fh = urllib.urlopen(o)
     state_stamp = StateStamp(fh.info())
@@ -218,3 +223,15 @@
   for w in workers:
     w.join()
   return 0
+
+
+def _GSPathExists(gsutil, path):
+  """Returns True if the GS path exists, False otherwise.
+
+  Args:
+    gsutil: Path to the gsutil binary to use.
+    path: The path to check for (gs://...).
+  """
+  cmd = [gsutil, 'stat', path]
+  ret, _, _ = RunCommand(cmd)
+  return ret == 0