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

Fix file truncation in Service Fabric commands #3796

Merged
merged 17 commits into from
Jun 29, 2017

Conversation

samedder
Copy link
Contributor

Fixes #3666 and adds automated testing to cover this case.

@codecov-io
Copy link

codecov-io commented Jun 21, 2017

Codecov Report

Merging #3796 into master will increase coverage by 0.18%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3796      +/-   ##
==========================================
+ Coverage   70.95%   71.14%   +0.18%     
==========================================
  Files         429      429              
  Lines       27154    27160       +6     
  Branches     4136     4137       +1     
==========================================
+ Hits        19268    19322      +54     
+ Misses       6623     6572      -51     
- Partials     1263     1266       +3
Impacted Files Coverage Δ
...zure-cli-sf/azure/cli/command_modules/sf/custom.py 52.87% <100%> (+12.33%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 178aed0...9fb59a7. Read the comment docs.

@troydai
Copy link
Contributor

troydai commented Jun 22, 2017

Please rebase and move your test files and recording files. The location of those files was moved in
#3848.

if os.path.isdir(abspath):
return abspath
else:
raise CLIError("Invalid path to application directory: {0}".format(abspath))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest a ValueError to be throw instead. The error here is not CLI specific but input parameter issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, fixed in latest push

if chunk != b'':
chunk = True
while chunk:
chunk = target_file.read(100000)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of curious why 100 000 bytes specifically?

Copy link
Contributor Author

@samedder samedder Jun 29, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's the amount we want to read before we print the next update saying we've read more of the file. For when a user specifies --show-progress

@@ -55,6 +56,38 @@ def app_type_returns_none_test(self, mock_config_parser):

self.cmd("az sf application type", checks=[NoneCheck()])

def valid_application_upload_path_returns_absolute_path_test(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this function used anywhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a test function, did you mean a different line?


# Specifically need a large temporary file in a temporary directory
temp_app_dir = tempfile.mkdtemp()
dest_app_dir = os.path.join(os.path.dirname(temp_app_dir), "tempdir00")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just create a folder under the current working directory? The logic here doesn't benefit from using tempfile.mkdtemp()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't sure if we could use cwd as a valid place to generate a file, hence the use of tempfile. I thought it would be a safer place to generate the directory.

fd, file_path = tempfile.mkstemp(dir=dest_app_dir)
os.close(fd)
dest_file_path = os.path.join(dest_app_dir, "tempfile00")
os.rename(file_path, dest_file_path)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

@samedder
Copy link
Contributor Author

@troydai Is it possible to get this added to the July 6 milestone?

@troydai troydai merged commit c8e6b37 into Azure:master Jun 29, 2017
@troydai
Copy link
Contributor

troydai commented Jun 29, 2017

It's in.

@samedder samedder deleted the fix_sf_large_file_upload branch June 29, 2017 21:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants