Skip to content

Commit 657cbfc

Browse files
committed
Use storage.open API correctly
Instead of downloading the file into a temporary file (`storage.open` and then `.read`) to save the file into another temporary file (our loop reading by chunks) we just use the `storage.open` response as the input of the `tarfile.open` function and extract it from there.
1 parent b5bb99c commit 657cbfc

File tree

1 file changed

+2
-10
lines changed

1 file changed

+2
-10
lines changed

readthedocs/projects/tasks.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -119,17 +119,9 @@ def pull_cached_environment(self):
119119
'msg': msg,
120120
}
121121
)
122-
_, tmp_filename = tempfile.mkstemp(suffix='.tar')
123122
remote_fd = storage.open(filename, mode='rb')
124-
with open(tmp_filename, mode='wb') as local_fd:
125-
local_fd.write(remote_fd.read())
126-
127-
with tarfile.open(tmp_filename) as tar:
128-
tar.extractall(self.version.project.doc_path)
129-
130-
# Cleanup the temporary file
131-
if os.path.exists(tmp_filename):
132-
os.remove(tmp_filename)
123+
with tarfile.open(fileobj=remote_fd) as tar:
124+
tar.extractall(self.project.doc_path)
133125

134126
def push_cached_environment(self):
135127
if not self.project.has_feature(feature_id=Feature.CACHED_ENVIRONMENT):

0 commit comments

Comments
 (0)