Raynes / fs

File system utilities for Clojure.
453 stars 119 forks source link

fix home function to actually query OS for users home directory #95

Open retrogradeorbit opened 9 years ago

retrogradeorbit commented 9 years ago

This resolves issue #12. I haven't tested it on windows, but on windows it will return nil, which is not ideal, but it never actually worked properly anyway, so it might be better.

$ lein midje
All checks (108) succeeded.
me.raynes.fs> (home "crispin")
#object[java.io.File 0x15eda628 "/home/crispin"]
me.raynes.fs> (home "www-data")
#object[java.io.File 0x620327b6 "/var/www"]
me.raynes.fs> (home "root")
#object[java.io.File 0x7358d81 "/root"]
me.raynes.fs> (home "missing-user")
nil
me.raynes.fs> (home "root;echo wat")
nil
Raynes commented 8 years ago

Any particular reason this would be better?

retrogradeorbit commented 7 years ago

It's better because the existing implementation returns the wrong directory for any non standard user, or any system with users laid out in multiple directory hierarchies. This patch returns the correct home directory for those users. For instance, running as a standard user (who has their home directory under /home/user) ask for the home directory of www-data; say (home "www-data") and the existing implementation returns "/home/www-data" which on my system is completely wrong. www-data's home directory is "/var/www". ask for home dir of "root" and you get "/home/root" not "/root". This patch returns the correct home directory for every user by querying the operating system.

Your comment here aludes to this problem:

https://github.com/Raynes/fs/blob/master/src/me/raynes/fs.clj#L27