-
Notifications
You must be signed in to change notification settings - Fork 8
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
Sync bonus round: sync:name, sync:purge, sync:check #165
Conversation
commands/project_sync.go
Outdated
if err != nil { | ||
fmt.Println(string(out)) | ||
fmt.Println(err.Error()) | ||
return cmd.Failure(string(out), "SYNC-VOLUME-FAILURE", 13) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I seem to always hit this condition. Here is a quick test script that always fails from me. It is set up to run from the rig project directory and use a locally built version of rig.
#!/bin/bash
set -e
DIR=purgetest
mkdir -p $DIR
./build/darwin/rig --verbose project sync:start --dir=$DIR
./build/darwin/rig --verbose project sync:stop --dir=$DIR
./build/darwin/rig --verbose project sync:purge --dir=$DIR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll note the underlying command that the --verbose flag causes to spit out seems to run without error and the return code when it finishes is 0. Perhaps it has something to do with tie-ing the out/err file handles together
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doing some experimenting it is the file handle tie-ing that is causing the issue. If I remove that part of the argument and remove the print of out in the case where the command succeeds it seems to run quietly which is what I thought the intention was.
Here is the diff that I tested.
diff --git a/commands/project_sync.go b/commands/project_sync.go
index ddfbee6..f27177b 100644
--- a/commands/project_sync.go
+++ b/commands/project_sync.go
@@ -278,13 +278,12 @@ func (cmd *ProjectSync) RunPurge(ctx *cli.Context) error {
cmd.out.Spin(fmt.Sprintf("Removing sync volume: %s", volumeName))
// @TODO capture the volume rm error text to display to user!
- out, err := util.Command("docker", "volume", "rm", volumeName, "1>&2").Output()
+ out, err := util.Command("docker", "volume", "rm", volumeName).Output()
if err != nil {
fmt.Println(string(out))
fmt.Println(err.Error())
return cmd.Failure(string(out), "SYNC-VOLUME-FAILURE", 13)
}
- fmt.Println(string(out))
return nil
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I get the panic too. Instead of Output()
we likely just need to use CombinedOutput()
will check that this makes the panic go away.
commands/project_sync.go
Outdated
|
||
// Remove sync fragment files. | ||
cmd.out.Spin("Removing .unison directories") | ||
if err := util.RemoveFileGlob("*.unison*", workingDir, cmd.out); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have a lot of experience with these fragment directories. Do both the directory names and all the files within them match the .unison pattern (which I believe they would need to in order for this cleanup to succeed).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested this with various files, here's an example:
.unison.._.DS_Store.94df3249bac7c3ee51c590d510133947.unison.tmp
I could not remember if I'd see something prefixing .unison
so went ahead to cover both.
Other than the notes I left with some questions and concerning the purge not seeming to work overall I think this is looking pretty good to me. |
@grayside I addresses a few things I saw in my review. I'm approving this, but wanted you to see the changes in case I changed any assumptions you had. Feel free to merge, or approve the additions and I can handle it. |
Not a golang expert and not set up to test this, but I like the new commands and the basic logic seems good. Also the pattern for purge cleanup looks good. I have several files right now on my local:
The |
I left the name here as |
Us: "Have you run doctor" |
Note that I'm still seeing some issues on the purge command but I don't think they are significant enough to hold up things since they revolve around the unison cleanup. Test script designed to be run from within the root of the repo after doing a build:
First issue I encountered appears to be a duplication of the base directory. Second is an lstat command failing that I haven't tracked down. Here is diff output that allows for some additional debugging (and avoids the duplicate base directory issue though I haven't fully tested it yet.
|
I found and address the double basepath, added some more verbose logging, and added a debug log message where I found the lstat error is throwing: just inside the callback for the filepath.Walk(). To reproduce this error run these commands:
This will output the following:
Despite the error, the process successfully removes our .unison file. So what could be going wrong? The file it's complaining about is not a symlink. If I create the file with After studying this, my theory is:
In order to fix that, we need to either keep track of the files removed and ignore them when they throw this specific error... or ignore errors on this because honestly it's a nice to have. Working on the latter, just a minute. |
Awesome, thanks for all the hard work @grayside |
This set of changes got just tangled enough that I've kept them together. If the time to separate them seems worth doing please say so and I'll take care of it.
Please note this is still a work in progress, and is shared now for context to ongoing unison discussions.
This PR adds the following:
rig project sync:name
to facilitate scripting against a project's unison container and volume.rig project sync:purge
to clean up/zero out the file sync for a clean slate restart.rig project sync:check
is a doctor check for unison. I'm not sure I want to usedoctor
, but that might happen. The goals of this are outlined more in Detect unison failure: unison doctor command? #163.I've also done some light refactoring to cleanup/streamline the sync code.
Fixes #163