file:list and symbolic links

Wednesday, 6 November 2019 · 4 messages · last reply 9 Nov 2019
ML
Marco Lettere6 Nov 2019 11:41 #
Dear all, what is the rationale behind the fact that file:list has been rewritten to not following symbolic links [1]? We had some jobs related code that relied on symlinks and stopped working after moving to new version of BaseX. Is there any work around? By using children or the new descendants functions maybe? Thanks for your support. Marco. [1] https://github.com/BaseXdb/basex/blob/bbb62d1ec3e10b4fa1cc48bd4e16911fa73e46df/basex-core/src/main/java/org/basex/query/func/file/FileList.java#L103
CG
Christian Grün9 Nov 2019 18:36 #
Hi Marco, The rationale is that symbolic links can lead to cycles if you have circular dependencies in your directory structure. What I learnt is that this happens quite frequently in practice. You can write an XQuery function with file:list and file:children, which recursively calls itself for each directory entry. The following function returns paths to all descendant files, excluding directories; it should follow all symbolic links:
  declare function file:traverse($dir) {
    for $child in file:children($dir)
    return if (file:is-dir($child)) then (
      file:traverse($child)
    ) else (
      $child
    )
  };
Hope this helps, Christian
Quoted text · Marco Lettere · 20 lines
On Wed, Nov 6, 2019 at 11:41 AM Marco Lettere <m.lettere at gmail.com> wrote: > > Dear all, > > what is the rationale behind the fact that file:list has been rewritten > to not following symbolic links [1]? > > We had some jobs related code that relied on symlinks and stopped > working after moving to new version of BaseX. > > Is there any work around? By using children or the new descendants > functions maybe? > > Thanks for your support. > > Marco. > > [1] > https://github.com/BaseXdb/basex/blob/bbb62d1ec3e10b4fa1cc48bd4e16911fa73e46df/basex-core/src/main/java/org/basex/query/func/file/FileList.java#L103 >
ML
Marco Lettere9 Nov 2019 18:55 #
I see your point Christian. Thank you. Of course recursively following the dir structure may work. Passing a boolean to switch the behaviour with a developer choice might be viable? Or is the file:list function standardized by xquery or expath spec? Have a nice weekend! M. Il sab 9 nov 2019, 18:36 Christian Grün <christian.gruen at gmail.com> ha scritto:
Quoted text · Christian Grün · 46 lines
> Hi Marco, > > The rationale is that symbolic links can lead to cycles if you have > circular dependencies in your directory structure. What I learnt is > that this happens quite frequently in practice. > > You can write an XQuery function with file:list and file:children, > which recursively calls itself for each directory entry. The following > function returns paths to all descendant files, excluding directories; > it should follow all symbolic links: > > declare function file:traverse($dir) { > for $child in file:children($dir) > return if (file:is-dir($child)) then ( > file:traverse($child) > ) else ( > $child > ) > }; > > Hope this helps, > Christian > > > On Wed, Nov 6, 2019 at 11:41 AM Marco Lettere <m.lettere at gmail.com> wrote: > > > > Dear all, > > > > what is the rationale behind the fact that file:list has been rewritten > > to not following symbolic links [1]? > > > > We had some jobs related code that relied on symlinks and stopped > > working after moving to new version of BaseX. > > > > Is there any work around? By using children or the new descendants > > functions maybe? > > > > Thanks for your support. > > > > Marco. > > > > [1] > > > https://github.com/BaseXdb/basex/blob/bbb62d1ec3e10b4fa1cc48bd4e16911fa73e46df/basex-core/src/main/java/org/basex/query/func/file/FileList.java#L103 > > >
CG
Christian Grün9 Nov 2019 19:06 #
Yes, file:list and file:children are included in version 1.0 of the EXPath spec. Looking back, an options argument for file:list (which can already have up to 3 arguments) would probably have been a better choice.
Quoted text · Marco Lettere · 59 lines
Marco Lettere <m.lettere at gmail.com> schrieb am Sa., 9. Nov. 2019, 18:55: > I see your point Christian. Thank you. > Of course recursively following the dir structure may work. > Passing a boolean to switch the behaviour with a developer choice might be > viable? Or is the file:list function standardized by xquery or expath spec? > Have a nice weekend! > M. > > Il sab 9 nov 2019, 18:36 Christian Grün <christian.gruen at gmail.com> ha > scritto: > >> Hi Marco, >> >> The rationale is that symbolic links can lead to cycles if you have >> circular dependencies in your directory structure. What I learnt is >> that this happens quite frequently in practice. >> >> You can write an XQuery function with file:list and file:children, >> which recursively calls itself for each directory entry. The following >> function returns paths to all descendant files, excluding directories; >> it should follow all symbolic links: >> >> declare function file:traverse($dir) { >> for $child in file:children($dir) >> return if (file:is-dir($child)) then ( >> file:traverse($child) >> ) else ( >> $child >> ) >> }; >> >> Hope this helps, >> Christian >> >> >> On Wed, Nov 6, 2019 at 11:41 AM Marco Lettere <m.lettere at gmail.com> >> wrote: >> > >> > Dear all, >> > >> > what is the rationale behind the fact that file:list has been rewritten >> > to not following symbolic links [1]? >> > >> > We had some jobs related code that relied on symlinks and stopped >> > working after moving to new version of BaseX. >> > >> > Is there any work around? By using children or the new descendants >> > functions maybe? >> > >> > Thanks for your support. >> > >> > Marco. >> > >> > [1] >> > >> https://github.com/BaseXdb/basex/blob/bbb62d1ec3e10b4fa1cc48bd4e16911fa73e46df/basex-core/src/main/java/org/basex/query/func/file/FileList.java#L103 >> > >> >

⚡Generated with XQuery