Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

storage: fix storage_update API #368

Merged
merged 1 commit into from
Nov 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 26 additions & 6 deletions mtda/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,21 +182,41 @@ def storage_status(self):

def storage_update(self, dest, src=None, callback=None):
path = dest if src is None else src
imgname = os.path.basename(path)
try:
st = os.stat(path)
imgsize = st.st_size
image = open(path, "rb")
image_size = st.st_size
except FileNotFoundError:
return False

status = self._impl.storage_update(dest, 0, self._session)
if status is False:
image.close()
return False
blksz = self._agent.blksz
impl = self._impl
session = self._session

# Get file handler from specified path
file = ImageFile.new(path, impl, session, blksz, callback)

# Open the shared storage device so we own it
self.storage_open()

try:
# Prepare for download/copy
file.prepare(image_size, CONSTS.IMAGE.RAW.value)

# Copy image to shared storage
file.copy()

# Wait for background writes to complete
file.flush()

self._impl.storage_compression(CONSTS.IMAGE.RAW.value, self._session)
return self._storage_write(image, imgname, imgsize, callback)
except Exception:
return False
finally:
# Storage may be closed now
self.storage_close()
return True

def storage_write_image(self, path, callback=None):
blksz = self._agent.blksz
Expand Down
2 changes: 0 additions & 2 deletions mtda/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -658,8 +658,6 @@ def storage_update(self, dst, offset, session=None):
else:
try:
result = self.storage_controller.update(dst, offset)
if result is True:
self._writer.start()
except (FileNotFoundError, IOError) as e:
self.mtda.debug(1, "main.storage_update(): "
"%s" % str(e.args[0]))
Expand Down