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

Token file sometimes malformed #91

Closed
DerGenaue opened this issue Jun 25, 2018 · 7 comments
Closed

Token file sometimes malformed #91

DerGenaue opened this issue Jun 25, 2018 · 7 comments
Labels

Comments

@DerGenaue
Copy link

I have a weird issue on one system where the token file is always malformed after login:

For some reason, it appends the last 4 chars of the last line in another new line:

<uname>
<token>
<time>
<token>
<time>
https://db5-client-s.gateway.messenger.live.com/v1
m/v1

This then results in the token file being unusable for the next start.
This only happens on one system (Debian 8, python 3.4, manually installed from repo).
It did not appear to happen, when SkPy is started with a correct token file.
It also isn't a new error; just one that can be avoided rather easily so I never really bothered.

Is this something known in any way?
The "w"-mode when writing that file should truncate it; could this nevertheless be a weird remainder in a buffer or something..? Any idea on how this could happen?
Do you think it might be worth it to just ignore excess lines when parsing the token file? (currently, excess lines fail parsing)

@Terrance
Copy link
Owner

Terrance commented Jun 25, 2018

Looks like this is specific to use of os.open():

>>> with open("test.txt", "w") as f:
...     f.write("11111111\n")
... 
>>> with open("test.txt", "w") as f:
...     f.write("2222\n")
... 
>>> with os.fdopen(os.open("test-fd.txt", os.O_WRONLY | os.O_CREAT, 0o600), "w") as f:
...     f.write("11111111\n")
... 
>>> with os.fdopen(os.open("test-fd.txt", os.O_WRONLY | os.O_CREAT, 0o600), "w") as f:
...     f.write("2222\n")
...
$ cat test.txt
2222
$ cat test-fd.txt
2222
111

Adding a call to f.truncate() before writing seems to cover it.

@Terrance Terrance added the bug label Jun 25, 2018
@DerGenaue
Copy link
Author

Oh nice; you were able to reproduce it..
I was searching for the bug in the code...
Is it specific to any of the versions?

@Terrance
Copy link
Owner

https://github.com/OllieTerrance/SkPy/blob/418b1f59d741527664105f31f2c603f538a2af6c/skpy/conn.py#L309-L322

It's been there since the beginning, so has most likely always been like this, though curiously I haven't come across it before.

@DerGenaue
Copy link
Author

DerGenaue commented Jun 25, 2018

I meant python versions 😂
my mistake

@Terrance
Copy link
Owner

Well it happens on 3.6 and 2.7, so plausibly all versions. In any case, should be handled now.

@DerGenaue
Copy link
Author

BTW... I think the reason might be that you "forgot" the os.O_TRUNC flag..?

@Terrance
Copy link
Owner

Huh, yup, that'd do it too...

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

No branches or pull requests

2 participants