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

Update #13 , Correct corner cases #14

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

rom3r4
Copy link

@rom3r4 rom3r4 commented Feb 5, 2021

Describe the change

  • Add return value to copy_file() issue 13
  • Correct Source is a directory
  • Correct Source does not exist
  • Correct Destination is a directory

Why are we doing this?

  • Change behaviour in copy_file() method

Benefits

  • Add a return value to copy_file() - as in copy_directory()
  • Treat corner-cases

Drawbacks

  • Regressions

Requirements

Put an X between brackets on each line if you have done the item:
[] Tests written & passing locally?
[] Code style checked?
[] Rebased with master branch?
[] Documentaion updated?

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
…does not exist, destination is a directory corner cases. piotrmurach#13
Copy link
Owner

@piotrmurach piotrmurach left a comment

Choose a reason for hiding this comment

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

Thank you for working on this. It's looking good but before I can merge, could you please make a few changes and add tests cases to copy_file_spec.rb that I mentioned in my comments. For the return value, you could possibly slightly modify the existing test cases. I'd also consider adding a test case for copying a file into a directory and handle the case when the source and destination paths are both directories.

Comment on lines +300 to +302
if ::File.directory? dest_path
dest_path = ::File.join(dest_path, ::File.basename(source_path))
end
Copy link
Owner

Choose a reason for hiding this comment

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

Good catch! However, I think we shouldn't change the destination path. If someone wants to copy a file to an existing directory, we should allow for it and the file collision will handle the situation when the file already exists. For example,

TTY::File.copy_file("foo/bar.rb", "baz/")
# => baz/bar.rb

Also, any changes like this require a test case.

Comment on lines +293 to +296
unless ::File.file? source_path
log_status(:error, source_path, verbose: verbose, color: :red)
return
end
Copy link
Owner

Choose a reason for hiding this comment

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

I believe this statement makes the directory check unreachable. Also, I much prefer to allow copying a file to a directory location rather than providing an error. Wouldn't you agree?


copy_metadata(source_path, dest_path, verbose: verbose, noop: noop,
color: color)
file_dest
Copy link
Owner

Choose a reason for hiding this comment

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

We need a test case that confirms this behaviour so that it stays true in future releases.

@@ -309,10 +319,11 @@ def copy_file(source_path, *args, context: nil, force: false, skip: false,
content = block[content] if block
content
end
return unless preserve
return file_dest unless preserve
Copy link
Owner

Choose a reason for hiding this comment

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

We need a test case that confirms this behaviour so that it stays true in future releases.

Comment on lines +66 to +69
if directory?
notify(:error, :red)
return
end
Copy link
Owner

Choose a reason for hiding this comment

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

I don't believe this is necessary if we allow copying a file to a directory destination. This should never be the case unless someone tries to copy a directory to directory, I guess we could test for that case. This would require another test case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants