rupa / z

z - jump around
Do What The F*ck You Want To Public License
16.4k stars 1.17k forks source link

Dereference symlinks for datafile #163

Closed ruduran closed 7 years ago

ruduran commented 9 years ago

As reported in #154, if the datafile is a symbolic link z overwrites it creating a regular file.

With this changes z dereferences de symlink and works with the actual file.

Any comments or suggestions are very welcome.

rupa commented 9 years ago

Unfortunately readlink isn't portable. Most unixlikes have it, but the options and usage varies a lot. For example, on OSX, and presumably BSD:

~$ readlink -nf .z
readlink: illegal option -- f
usage: readlink [-n] [file ...]
ruduran commented 9 years ago

I just realised we could just use cp instead of mv. Is there any reason why it cannot be used?

rupa commented 9 years ago

cp is not atomic, so the datafile can (and will) get clobbered. That's why the whole cumbersome temp file and mv (which is atomic) process is there in the first place :)

ruduran commented 9 years ago

Understood, i'll try to find a better approach then :)

ruduran commented 9 years ago

I'm still using readlink, but the command without any argument should be portable, isn't it?

rbartoli commented 8 years ago

@ruduran Hi, I'm interested in implementing the same functionality (as I added support for z in mackup).

I cloned your fork and tested it on Mac OS X and it seems to work properly so I can confirm that readline with no argument should be portable.

Have you tested it on Linux?

ruduran commented 8 years ago

Yes, I did in fact develop it on Linux and it seemed to work just fine :)

rbartoli commented 8 years ago

@ruduran nice, thanks for confirming!

@rupa what do you think is the next step on this?

rupa commented 7 years ago

seems reasonable as it works ok with no args to readlink, wanna leave this open so i don't forget about it

ruduran commented 7 years ago

Ok, I had just closed it because nobody seemed interested. Glad to see I was wrong :)

rupa commented 7 years ago

yeah im just real conservative about changing things at this point, there's enough people using this with weirdo setups that it's easy to fix things for one use case and break another. inclined to do this tho, cause if someone has some silly readlink or doesn't have it at all, the solution is "don't symlink the datafile, which you couldn't do before anyway"