Skip to content

Implement remote to local directory copying + Bugfixes#20

Merged
noorvir merged 9 commits intomasterfrom
unw-192-3
Jun 7, 2023
Merged

Implement remote to local directory copying + Bugfixes#20
noorvir merged 9 commits intomasterfrom
unw-192-3

Conversation

@caldempsey
Copy link
Copy Markdown
Contributor

@caldempsey caldempsey commented Jun 7, 2023

This PR:

  • Acts as a fast follow to previous feedback.
  • Implements remote to local directory copying via the archive process.
  • Cleans up a case where the only key used was id_rsa or whatever key was specified in a user's extended SSH hosts config.
  • Fixes a bug where users could not specify their own SSH key.
  • Fixes a bug where directories would not be copied from local to remote via the archiving process consistently.
  • Some naming updates.
  • Resolves UNW-192
🔄 Copying root@216.153.52.254:/home/unweave => /home/mmacheerpuppy/bar
🧳 Gathering context from "root@216.153.52.254:/home/unweave"
📦 Copying the archive of the remote path to the host...
🗜️ Unzipping the copied archive to the local directory...
✅  Copied root@216.153.52.254:/home/unweave => /home/mmacheerpuppy/bar

@caldempsey caldempsey requested a review from noorvir June 7, 2023 13:30
@caldempsey caldempsey changed the title [UNW-192] Implement remote to local directory copying + Bugfixes [UNW-192-3] Implement remote to local directory copying + Bugfixes Jun 7, 2023
cmd/copy.go Outdated

func isLocalDirToRemoteCopy(args []string) bool {
if strings.Contains(args[0], "sess:") {
func shouldCopyLocalDirToRemote(localPath1, remotePath2 string) bool {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I suggest not adding numbers to variable names.

Copy link
Copy Markdown
Contributor Author

@caldempsey caldempsey Jun 7, 2023

Choose a reason for hiding this comment

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

for context, this is to help clarify the local path should be the first argument and the remote path should be the second argument, i.e. given a list of args["sess:remote/path", "/local/path"] or the converse args[ "/local/path", "sess:remote/path"] for the other function shouldCopyRemoteDirToLocal

it's still not clear from the variable naming alone, the first argument needs to be the local path and the second argument needs to be the remote path or vice versa.

so, im not sure what a good solution to this is other than to indicate localPath1 as 'the first argument that we also expect to be the local path' and 'remotePath2' as 'the second argument that we also expect to be the remotePath'.

any ideas how we could name this?

Copy link
Copy Markdown
Contributor Author

@caldempsey caldempsey Jun 7, 2023

Choose a reason for hiding this comment

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

edit: i've updated this to remove the second argument on the whole and that gets rid of the numbers from the variable names, seemed superfluous

but i don't know about not adding numbers to variable names as a blanket rule, especially if we need to indicate some kind of ordinal

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The variable names in a function signature should ideally be descriptive and not denote their positions. The position of a parameter in a function is determined by its place in the function definition itself, not by its name.

I suggest
func shouldCopyLocalDirToRemote(localPath, remotePath string) bool {

Copy link
Copy Markdown
Contributor Author

@caldempsey caldempsey Jun 7, 2023

Choose a reason for hiding this comment

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

i think in this case the intent of the positions was to also denote some sense of directionality, but yes this was likely overthought, either way its been removed now, thanks for commenting !

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'd agree to keep numbers out of names. I don't think there's a rule but just looks off.
Shorter names are better. So in this case some thing a and b is idiomatic in go. The standard library uses it all over the place.

Copy link
Copy Markdown
Contributor Author

@caldempsey caldempsey Jun 7, 2023

Choose a reason for hiding this comment

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

I think shorter names can be better but I think they also need to be use judiciously because they can muddy a codebase or make logic borderline unreadable because you can lose context on what kind of operation a variable is intended to perform.

So, I think short names are fine as long as they preserve the context of what the code is doing. But if you lose context i.e. you change remotePath and localPath to just 'path' then it's completely unclear whether you intend to take the remotePath or localPath as an argument.

However in defense of this, I think from is probably descriptive enough, and I think that captures all the above.

Copy link
Copy Markdown
Contributor Author

@caldempsey caldempsey Jun 7, 2023

Choose a reason for hiding this comment

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

So instead of func shouldCopyLocalDirToRemote(remotePath) we use func shouldCopyLocalDirToRemote(from string)

Ideally I would have

func shouldCopyLocalDirToRemote(from Path) where Path aliases a type declaration for strings, because it's not clear from 'from string' that the from string needs to be a validated abspath, but I think that's a bit much for our use cases right now.

There have definitely been cases in the past where the why of business logic has been lost because of single letter variable names, resulting in bad refactors.

@caldempsey caldempsey requested a review from octohedron June 7, 2023 14:06
cmd/ssh.go Outdated
}

// zipRemoteDirectory takes an ssh target, and zips up the contents of that target to a returned in the remote /tmp
func zipRemoteDirectory(sshTarget, privateKeyPath string) (remoteArchiveLoc string, err error) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Let's call this tarRemoteDirectory

@noorvir noorvir changed the title [UNW-192-3] Implement remote to local directory copying + Bugfixes Implement remote to local directory copying + Bugfixes Jun 7, 2023
@noorvir noorvir merged commit e9ba941 into master Jun 7, 2023
@noorvir noorvir deleted the unw-192-3 branch June 7, 2023 14:54
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.

3 participants