summarylogtreecommitdiffstats
path: root/gsutil-use-google-cloud-sdk.patch
blob: 89549951f7651c7840acdb145df8ceed775bd00d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
diff --git a/gsutil.py b/gsutil.py
index 8bfed540e..cca9d4b50 100755
--- a/gsutil.py
+++ b/gsutil.py
@@ -82,45 +82,10 @@ def temporary_directory(base):
       shutil.rmtree(tmpdir)
 
 def ensure_gsutil(version, target, clean):
-  bin_dir = os.path.join(target, 'gsutil_%s' % version)
-  gsutil_bin = os.path.join(bin_dir, 'gsutil', 'gsutil')
-  gsutil_flag = os.path.join(bin_dir, 'gsutil', 'install.flag')
-  # We assume that if gsutil_flag exists, then we have a good version
-  # of the gsutil package.
-  if not clean and os.path.isfile(gsutil_flag):
-    # Everything is awesome! we're all done here.
-    return gsutil_bin
-
-  if not os.path.exists(target):
-    os.makedirs(target)
-  with temporary_directory(target) as instance_dir:
-    # Clean up if we're redownloading a corrupted gsutil.
-    cleanup_path = os.path.join(instance_dir, 'clean')
-    try:
-      os.rename(bin_dir, cleanup_path)
-    except (OSError, IOError):
-      cleanup_path = None
-    if cleanup_path:
-      shutil.rmtree(cleanup_path)
-
-    download_dir = os.path.join(instance_dir, 'download')
-    target_zip_filename = download_gsutil(version, instance_dir)
-    with zipfile.ZipFile(target_zip_filename, 'r') as target_zip:
-      target_zip.extractall(download_dir)
-
-    try:
-      os.rename(download_dir, bin_dir)
-    except (OSError, IOError):
-      # Something else did this in parallel.
-      pass
-    # Final check that the gsutil bin exists.  This should never fail.
-    if not os.path.isfile(gsutil_bin):
-      raise InvalidGsutilError()
-    # Drop a flag file.
-    with open(gsutil_flag, 'w') as f:
-      f.write('This flag file is dropped by gsutil.py')
-
-  return gsutil_bin
+  candidate = '/opt/google-cloud-sdk/platform/gsutil/gsutil'
+  if os.path.exists(candidate):
+    return candidate
+  raise RuntimeError('Please install google-cloud-sdk package to use gsutil')
 
 
 def run_gsutil(force_version, fallback, target, args, clean=False):