-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Improved fix for Unicode mistakes in atomic move #4209
Conversation
Fixes #4168. Also closes #4192, which it supersedes. The original problem is that this implementation used bytestrings incorrectly to invoke `mktemp`. However, `mktemp` is deprecated, so this PR just avoids it altogether. Fortunately, the non-deprecated APIs in `tempfile` support all-bytes arguments.
Paging @catap, @LeoSebal, and @dertuxmalwieder to please try out this improved fix, which supersedes #4192. |
I am currently using the patch from #4192 to move files from my local hard disk to a NAS and it has not crashed for me. But I will try your patch and see if I notice any difference. :-) |
@sampsyo the strange things that I’m used original code and it works fine :) anyway, I run it on macOS and probably it is OS specific things |
This patch reintroduces the old bug:
|
Thanks for trying it out, everybody! @dertuxmalwieder, do you have the complete traceback I could look at? |
I already undid the patch, I am currently running beets over my whole collection, that will take a while... (If nobody else does...) |
This is mostly "defensive programming": clients *should* only call this on bytestring paths, but just in case this gets called on a Unicode string path, we should now not crash.
Awesome; thanks! It's partially a stab in the dark, but I have pushed an additional tweak that should almost certainly avoid that kind of problem in the odd cases where it might arise. |
It seems to be hard to reproduce the crashes as there does not seem to be a pattern. |
I've only had a very brief look at this (and I haven't read the issues and PRs leading up to this one); but I'm not sure this fix is fully consistent yet: You're now using |
Ah, you're very right about that, @wisp3rwind. Thanks for the sanity check. Let me try simplifying things with |
OK, let's give the above commit a try. The result may look a little ugly, but I think it's the right thing. The strategy is:
|
This seems to be a stubborn problem (IIRC, I'm at least partially responsible for reviewing the original PR...), thanks for dealing with it!
I see what you mean, but I also can't think of a way to improve things.
I would claim that this is superfluous, if anything is calling
Sounds correct to me 👍 |
While we're at it, the two |
Yeah, you're absolutely right that this should be considered a bug. I was just trying to "defensively program" here: to tolerate those bugs instead of crashing, just because I'm not terribly confident that every client does the right thing (given the other tracebacks I've seen). It would be good, in some future iteration, to back away from this and actually enforce this requirement (with
Yep, good call. I'll add these. |
Alright, with that little bit of evolution out of the way, I would be ever so grateful if the interested parties could give this a shot! I'm reasonably confident in it, however, so I'd like to merge this soonish if there are no obvious red flags. |
It seems to be working on my end! I was having this issue before and your fix works. Thank you much! |
OK, awesome, thanks, @nopeinomicon! I'll call this working for now—if anyone discovers any trouble down the line, we can amend. |
Will there be a bugfix version with this fix any time soon? |
The original problem was that this implementation of atomic moves, in #4060, used bytestrings incorrectly to invoke
mktemp
. This caused a regression that crashed beets when it tried to move files across filesystems (which, of course, actually involves a copy).However,
mktemp
is deprecated, so this PR just avoids it altogether. Fortunately, the non-deprecated APIs intempfile
support all-bytes arguments.Fixes #4168. Also closes #4192, which it supersedes.