Web lists-archives.com

Re: link vs file




I am writing a search function for file system branch designated by user in
interface elements (php/html page). So if there is a hard link in this file
system branch that point to an existing file in the same system branch, I don't necessarily want to
search the file more than once.

To find hard links, you'll have to ask the OS for help (which sort of eliminates your approach), https://unix.stackexchange.com/questions/201920/how-to-find-all-hard-links-to-a-given-file has a reasonable explanation of an OS based approach (assuming *nix)

HTH

Op ma 17 dec. 2018 om 23:50 schreef Jeffry Killen <jekillen@xxxxxxxxxxx>:
Thanks for the crash course in links.

I am writing a search function for file system branch designated by user in
interface elements (php/html page). So if there is a hard link in this file
system branch that point to an existing file in the same system branch, I don't necessarily want to
search the file more than once.

My limited understanding of hard vs soft links is that hard links can only be made on file in the
same file system. But I was never clear on what the "same" file system limit is.

For instance: suppose I put a hard link in the usr filesystem that points to a file in the var file
system, is that valid? What if the usr and var directories are on separate hard drives? I set once
set up a FreeBSD system with usr on one SCSI drive and var on another SCSI drive on the
same machine. These two SCSI drives were separate from the boot drive.  Would that constitute
"different" file systems? This has been 10 or more years ago and most of my serious Linux/BSD
adventures have been 10 or more years ago.

Perhaps I could get directions to a decent explanation.

By the way, duh, I figured out why http://localhost/indexLink was producing raw php code:
It doesn't have the .php extension.

Thanks for time and attention;
Jeff K
> On Dec 17, 2018, at 1:54 PM, Serge Fonville <serge.fonville@xxxxxxxxx> wrote:
>
> I did manage to figure out that link creates a hard link. And that I should have used
> symlink() instead. But how would a hard link be detected
> Every file is a link to a location on the filesystem, normally when you create a file, you allocate an entry on the filesystem and create a link. This happens implicitly when creating a file.
> So every file has one hard link pointing to it. Additional hard links are just that, hard links, which happen to point to the same file structure inside the filesystem. When all hard links are removed, the file is still there,
> but nothing points to it.
>
> HTH
>
> Op ma 17 dec. 2018 om 22:44 schreef Jeffry Killen <jekillen@xxxxxxxxxxx>:
> I did manage to figure out that link creates a hard link. And that I should have used
> symlink() instead. But how would a hard link be detected?
> JK
> > On Dec 17, 2018, at 1:27 PM, Jeffry Killen <jekillen@xxxxxxxxxxx> wrote:
> >
> > Hello:
> >
> > I am trying to get a feel for the difference
> > between is_link and is_file.
> >
> > So I ran this code: the result is in comment block at the bottom
> >
> > <?php
> > if(link('index.php', 'indexLink') === false)
> >  {
> >   print "link failed";
> >  }
> > else
> >  {
> >   $_linkRes = 'false';
> >   $_fileRes = 'false';
> >   if(is_link('indexLink'))
> >     {
> >      $_linkRes = 'true';
> >     }
> >   else if(is_file('indexLink'))
> >     {
> >      $_fileRes = 'true';
> >     }
> >   print 'indexLink: link; '.$_linkRes."<br>";
> >   print 'indexLink: file; '.$_fileRes;
> >  }
> > /*
> > output:
> > indexLink: link; false
> > indexLink: file; true
> > */
> > ?>
> >
> > Why is it returning false for link and true for file?
> >
> > This is an apache/php v 5.3x installation on Mac Yosemite.
> >
> > Forgive my ignorance, but I have not worked with links up
> > to this point. If I load http://localhost/indexLink I get a ton
> > of raw code and some html rendered.
> >
> > Thank you for time and attention
> > JK
>