Page 1 of 1

I hadn't thought about ln -s for this..

Posted: Mon Oct 09, 2017 11:11 am
by jlowe
This may be common, just hadn't thought of it before.

I had two programs "getData.py" and "putData.py" that were the same, except the source/destination are reversed - the working source/destination directory are similar and
use os.getcwd().split to get the parts I needed . I started to use command line options to combine into one program, then it dawned on me to use symbolic links.

Code: Select all

ln -s getData.v0.1.py   getData.py
ln -s getData.py putData.py
getData.v0.1.py, uses sys.argv[0] to reverse src/destination:

Code: Select all

...

# something like this to fort locations
# - default getData 
fromDir = "/otherplace/"+os.getwd().split("somelevel")[1]  
toDir = os.getcwd()

if "putData"  in sys.argv[0]:
   fromDir,  toDir = toDir, fromDir
...   

..jay

Re: I hadn't thought about ln -s for this..

Posted: Mon Oct 09, 2017 11:16 am
by Heater
That's exactly what busybox does.

busybox is a single executable that contains a lot of common Linux commands, cp, ls, mv, rmdir, etc, etc. Designed for small memory systems. It uses symbolic links called cp, ls, mv, rmdir, etc, etc that all link to the same executable which then uses argv[0] to decide what to do.

Re: I hadn't thought about ln -s for this..

Posted: Mon Oct 09, 2017 11:52 am
by jahboater
Do you even need symbolic links since they are in the same filesystem, same directory even?
Try without the "-s".
You just end up with several different names for the one file.

Re: I hadn't thought about ln -s for this..

Posted: Mon Oct 09, 2017 11:53 am
by jahboater
Do you even need symbolic links since they are in the same filesystem, same directory even?
Try without the "-s".
You just end up with several different names for the one file (multiple files with the same inode number).

Re: I hadn't thought about ln -s for this..

Posted: Mon Oct 09, 2017 1:11 pm
by jlowe
Maybe I'll should spend a little time looking at busybox source..

and I use ln -s in this case as it is uses across file systems, and mostly so I don't rm the original.
by mistake.

.thanks for the comments .. still learning..

..jay

Re: I hadn't thought about ln -s for this..

Posted: Mon Oct 09, 2017 1:42 pm
by Martin Frezman
and I use ln -s in this case as it is uses across file systems, and mostly so I don't rm the original by mistake.
Actually, that is a prime reason for using hard links rather than symlinks. When I first read the OP, my first thought was that if you use hard links, you are less likely to accidentally remove the original file, because when using hard links, all links are of equal status.

If you use symlinks, then if you remove the original file, all the symlinks become useless.

Of course, the ability to link across filesystems is also significant, although on the RPi, the general model seems to be having everything all on one filesystem, so ...

Re: I hadn't thought about ln -s for this..

Posted: Mon Oct 09, 2017 2:25 pm
by jlowe
.. I use NFS as a "MASTER" and access across multiple rPi's -

However, I may be using links incorrectly.. ..

in a development directory:

Code: Select all

ln -s $PWD/dosomething.v01.py   dosomething.py
sudo ln -s $PWD/dosomething.py /usr/local/bin/dosomething.py
When I change to a new version of code, I just relink it to dosomething.py without sudo.
This is all done in one file system.

BTW.. I appreciate everyone's comments...

thanks
..jay