jlowe
Posts: 18
Joined: Wed Apr 29, 2015 1:27 am

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

Mon Oct 09, 2017 11:11 am

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

Heater
Posts: 13691
Joined: Tue Jul 17, 2012 3:02 pm

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

Mon Oct 09, 2017 11:16 am

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.
Memory in C++ is a leaky abstraction .

jahboater
Posts: 4778
Joined: Wed Feb 04, 2015 6:38 pm

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

Mon Oct 09, 2017 11:52 am

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.

jahboater
Posts: 4778
Joined: Wed Feb 04, 2015 6:38 pm

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

Mon Oct 09, 2017 11:53 am

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).

jlowe
Posts: 18
Joined: Wed Apr 29, 2015 1:27 am

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

Mon Oct 09, 2017 1:11 pm

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

Martin Frezman
Posts: 1020
Joined: Mon Oct 31, 2016 10:05 am

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

Mon Oct 09, 2017 1:42 pm

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 ...
If this post appears in the wrong forums category, my apologies.

jlowe
Posts: 18
Joined: Wed Apr 29, 2015 1:27 am

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

Mon Oct 09, 2017 2:25 pm

.. 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

Return to “General programming discussion”