Skip to content

Commit 89a202d

Browse files
MohammadAGfahhem
authored andcommitted
Close file object after pushing (google#79)
* Close file object after pushing * Only close file if we opened it
1 parent 69754a7 commit 89a202d

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

adb/adb_commands.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,18 +165,22 @@ def Push(self, source_file, device_filename, mtime='0', timeout_ms=None):
165165
mtime: Optional, modification time to set on the file.
166166
timeout_ms: Expected timeout for any part of the push.
167167
"""
168+
should_close = False
168169
if isinstance(source_file, str):
169170
if os.path.isdir(source_file):
170171
self.Shell("mkdir " + device_filename)
171172
for f in os.listdir(source_file):
172173
self.Push(os.path.join(source_file, f), device_filename + '/' + f)
173174
return
174175
source_file = open(source_file, "rb")
176+
should_close = True
175177

176178
connection = self.protocol_handler.Open(
177179
self.handle, destination=b'sync:', timeout_ms=timeout_ms)
178180
self.filesync_handler.Push(connection, source_file, device_filename,
179181
mtime=int(mtime))
182+
if should_close:
183+
source_file.close()
180184
connection.Close()
181185

182186
def Pull(self, device_filename, dest_file='', timeout_ms=None):

0 commit comments

Comments
 (0)