Add sanity check to archiving script

As discussed offline, we may inadvertently cherry pick a cl to our
release branch without updating the version file, and the bots would
overwrite the original bits for the existing version

This will now raise and exit non zero, making the bot red!

Change-Id: I6b574c7c3d7558ef8cf59de18c9c5e15296d95f2
diff --git a/tools/archive.py b/tools/archive.py
index 0844eea..360a0ee 100755
--- a/tools/archive.py
+++ b/tools/archive.py
@@ -51,9 +51,12 @@
 
 def GetStorageDestination(storage_prefix, version, file_name, is_master):
   # We archive master commits under raw/master instead of directly under raw
+  version_dir = GetVersionDestination(storage_prefix, version, is_master)
+  return '%s/%s' % (version_dir, file_name)
+
+def GetVersionDestination(storage_prefix, version, is_master):
   archive_dir = 'raw/master' if is_master else 'raw'
-  return '%s%s/%s/%s/%s' % (storage_prefix, ARCHIVE_BUCKET, archive_dir,
-                            version, file_name)
+  return '%s%s/%s/%s' % (storage_prefix, ARCHIVE_BUCKET, archive_dir, version)
 
 def GetUploadDestination(version, file_name, is_master):
   return GetStorageDestination('gs://', version, file_name, is_master)
@@ -81,6 +84,9 @@
     print 'On master, using git hash for archiving'
     version = GetGitHash()
 
+  destination = GetVersionDestination('gs://', version, is_master)
+  if utils.cloud_storage_exists(destination):
+    raise Exception('Target archive directory %s already exists' % destination)
   with utils.TempDir() as temp:
     version_file = os.path.join(temp, 'r8-version.properties')
     with open(version_file,'w') as version_writer: