refers to the same inode/file

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

refers to the same inode/file

iler.ml

In vimscript, how do I compare whether two pathnames refer to
same file (does "../../symlink1" and "/home/joe/file1" refer to same
inode ?)

This is what's normally done with stat() and comparing inode &
device in unix, or what 'test x -ef y' in bash/shell does;  ignores
differences in abolute vs relative pathnames, and resolving all
symlinks.

Thanks

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: refers to the same inode/file

John Little-4

:h resolve()

Regards, John
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: refers to the same inode/file

iler.ml

Thanks for the resolve() lead.

For the record, It turns out that resolve() resolves symlinks but does
not make them absolute.
For example if if path1== "/home/joe" and path2 == "." and current dir
is "/home/joe",
expression (resolve(path1) == resolve(path2)) is  false.

The following does the trick for me:

func! ResolveAndMakeAbsolute(path)
    let r = expand(a:path)
    return r[0] == '/' ? resolve(r) : getcwd() . "/" . r
endfun


(which breaks on Windows but that is another story).

On Mar 17, 5:17 am, John Little <[hidden email]> wrote:
> :h resolve()
>
> Regards, John
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: refers to the same inode/file

iler.ml

func! ResolveAndMakeAbsolute(path)
    let r = expand(a:path)
    return r[0] == '/' ? resolve(r) : resolve(getcwd() . "/" . r)
endfun

On Mar 17, 11:59 am, Yakov <[hidden email]> wrote:

> Thanks for the resolve() lead.
>
> For the record, It turns out that resolve() resolves symlinks but does
> not make them absolute.
> For example if if path1== "/home/joe" and path2 == "." and current dir
> is "/home/joe",
> expression (resolve(path1) == resolve(path2)) is  false.
>
> The following does the trick for me:
>
> func! ResolveAndMakeAbsolute(path)
>     let r = expand(a:path)
>     return r[0] == '/' ? resolve(r) : getcwd() . "/" . r
> endfun
>
> (which breaks on Windows but that is another story).
>
> On Mar 17, 5:17 am, John Little <[hidden email]> wrote:
>
> > :h resolve()
>
> > Regards, John
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: refers to the same inode/file

Andy Wokula

Yakov schrieb:
> func! ResolveAndMakeAbsolute(path)
>     let r = expand(a:path)
>     return r[0] == '/' ? resolve(r) : resolve(getcwd() . "/" . r)
> endfun

There is also
    :h simplify()

--
Andy


--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: refers to the same inode/file

Tony Mechelynck
In reply to this post by iler.ml

On 17/03/09 10:59, Yakov wrote:

>
> Thanks for the resolve() lead.
>
> For the record, It turns out that resolve() resolves symlinks but does
> not make them absolute.
> For example if if path1== "/home/joe" and path2 == "." and current dir
> is "/home/joe",
> expression (resolve(path1) == resolve(path2)) is  false.
>
> The following does the trick for me:
>
> func! ResolveAndMakeAbsolute(path)
>      let r = expand(a:path)
>      return r[0] == '/' ? resolve(r) : getcwd() . "/" . r
> endfun
>
>
> (which breaks on Windows but that is another story).
>
> On Mar 17, 5:17 am, John Little<[hidden email]>  wrote:
>> :h resolve()
>>
>> Regards, John


On any system, you can resolve symlinks and get the absolute path by

        fnamemodify(resolve(filename), ':p')

which will also make sure there is a / at the end if it is a directory.
However, on systems like W-NT and Unix where hardlinks exist, i.e. where
it is possible to have, in a valid way, two (or more) directory entries
pointing to the same data without one of them being a shortcut (a
symlink) to the other, you'll still get different values if you use
different hardlinks to the same data as the filename. To resolve
hardlink synonyms, you'd need a function giving both the partition
(maybe E: on Windows, /dev/sda3 on Linux, etc.) and also the FAT cluster
number or the inode number, as a function of the full pathname (of the
file or folder) after resolving all softlinks or shortcuts like above. I
don't know whether Vim possesses such a function (or couple of functions).


Best regards,
Tony.
--
An elephant is a mouse with an operating system.

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: refers to the same inode/file

Tim Chase

> different hardlinks to the same data as the filename. To resolve
> hardlink synonyms, you'd need a function giving both the partition
> (maybe E: on Windows, /dev/sda3 on Linux, etc.) and also the FAT cluster
> number or the inode number, as a function of the full pathname (of the
> file or folder) after resolving all softlinks or shortcuts like above.

There even more complications -- things like SUBST'ed drives on
Windows, and network shares offering up the same file (whether
hardlinked or not) in multiple locations.

-tim




--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---