AstraLuma / xontrib-z

Tracks your most used directories, based on 'frecency'.
GNU General Public License v3.0
24 stars 16 forks source link

Guard against corrupt data file #14

Closed con-f-use closed 5 years ago

con-f-use commented 5 years ago

Works around corrupted data files that would otherwise throw an exception on every command execution entered in any xonsh shell that has xontrib-z activated.

This happened to me, when I changed dir into a folder that had a newline in it. The resulting data-file looked something like this:

/home/confus|425|1558040766
/home/confus/devel/suckless/st|58|1557794303
/tmp|29|1554672991
/tmp/data_is_
xs2|29|1554672999
/home|2|1553968033
/home/confus/.local/bin|4|1556291677
/home/confus/.local|1|1556298881
/home/confus/devel/suckless|3|1557707138

Note the superfuous linebreak in the 4th line after /tmp/data_is_ and how the line continues with xs2|29|1554672999. Results in a traceback on every command executed in shell.

If I find the the time, I will modify the save_data and load_data function so it escapes resp. unescapes special characters. I think escaping the pipe \| and newline \n should be sufficient, but there might be other weird special cases like terminal bell, backspace and the like.

con-f-use commented 5 years ago

The last commit was not (yet) thorough tested. Will try to in the future unless someone else is faster.

AstraLuma commented 5 years ago

Should I consider this WIP or is it ready to go?

How does the original script handle this? The data format was chosen to maintain compatibility with the original script.

con-f-use commented 5 years ago

The original script doesn't and neither does fasd (which is supposed to be an improvement). Both just write the path "as is" and then ignore any invalid directories that resutlt form it. They just don't cd into them and give no error message. The invalid lines stay in the file.

It's still a WIP, but I'll probably finish today.

con-f-use commented 5 years ago

Okay, now it is done and ready for merge.