user.dir and BaseX Add Command

Friday, 29 November 2013 · 5 messages · last reply 3 Dec 2013
SG
Simon Görke29 Nov 2013 10:41 #
Hi together, I have a question regarding the baseX add command. We change the user.dir system property in the basexserver.bat as shown below:
java -Duser.dir=c:/tmp -cp "%CP%" %VM% org.basex.BaseXServer %*
This is done with the background of defining an export/import directory without using absolute paths with the add command itself (we deploy our setup from version control to different directory environments, and it should work "out-of-the-box"). 1. With exporting, this seems to work fine except for a minor issue: in addition to the successful export to c:\tmp, an empty folder is created in the basex/bin directory with the name of the exported db. 2. With adding, we always get the error message " Resource "C:/tmp/test.xml" not found.", even if test.xml exists in the filesystem at c:\tmp. However, if we copy test.xml to the basex/bin-folder, the add command is successful. It seems that though the error message relates to the correct (modified) path, baseX uses the default one when trying to add the file? Would it be possible to fix this issue, or is there another way to achieve the intended behavior? Best Regards Simon
CG
Christian Grün30 Nov 2013 18:18 #
Hi Simon,
Quoted text · Simon Görke · 3 lines
> 1. With exporting, this seems to work fine except for a minor issue: in > addition to the successful export to c:\tmp, an empty folder is created in > the basex/bin directory with the name of the exported db.
I didn’t manage to reproduce this; could you please provide us with an SSCCE (e.g. a little bxs script [1] that contains all the steps required)? Christian [1] http://docs.basex.org/wiki/Commands#Command_Scripts
Quoted text · Simon Görke · 22 lines
> > 2. With adding, we always get the error message " Resource "C:/tmp/test.xml" > not found.", even if test.xml exists in the filesystem at c:\tmp. > However, if we copy test.xml to the basex/bin-folder, the add command is > successful. > It seems that though the error message relates to the correct (modified) > path, baseX uses the default one when trying to add the file? > > Would it be possible to fix this issue, or is there another way to achieve > the intended behavior? > > > Best Regards > Simon > > > > > _______________________________________________ > BaseX-Talk mailing list > BaseX-Talk at mailman.uni-konstanz.de > https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk
SG
Simon Görke30 Nov 2013 20:15 #
Hi Christian, thanks for your help.
Quoted text · Christian Grün · 3 lines
> > I didn’t manage to reproduce this; could you please provide us with an > SSCCE
Sure:
<commands>
   <create-db name='test'/>
   <add path='newdoc'><xyz/></add>
   <export path='testdb' />
</commands>
When I 1) start the modified basexserver.bat (with last line replaced by java -Duser.dir=C:/tmp -cp "%CP%" %VM% org.basex.BaseXServer %*) and 2) call basexclient -c cmd.xml with the content above, I get an empty testdb folder in basex/bin and a testdb folder containing newdoc in c:\tmp (of course, c:\tmp existed before). Two more notes: 1) While testing the script, I noticed that my initial description was a bit imprecise: actually, the folder which is created in basex/bin is not named from the database, but from the path='xxx' option given in the export command (i.e. "testdb" for the example above, and not 'test'; unfortunately both were identical in my initial tests). 2) Additionally I found out that the behavior is different when the database is empty: in this case, the folder structure is still created in basex/bin, but *not* in the user.dir path. I do not know what is intended for the export of an empty database - creation of the (empty) export folder structure, or no filesystem operations at all? Thanks for your help, Greets Simon
CG
Christian Grün1 Dec 2013 14:12 #
Hi Simon, The reason for the trouble was the following Java operations do different things if user.dir is changed: new File("X").mkdirs() new File("X").getAbsoluteFile().mkdirs() I’ve rewritten our file operations such that they are always resolved against the absolute file path. I can’t promise that everyone works fine now (I remember some forum posting that discouraged the use of user.dir, probably because of reasons like the one above), so I’m interested in your feedback on the new snapshot [1]. Best, Christian [1] http://files.basex.org/releases/latest/
Quoted text · Simon Görke · 41 lines
On Sat, Nov 30, 2013 at 8:15 PM, Simon Görke <simon.goerke at ils.uni-stuttgart.de> wrote: > Hi Christian, > > thanks for your help. > > >> >> I didn’t manage to reproduce this; could you please provide us with an >> SSCCE > > Sure: > > <commands> > <create-db name='test'/> > <add path='newdoc'><xyz/></add> > <export path='testdb' /> > </commands> > > When I 1) start the modified basexserver.bat (with last line replaced by > java -Duser.dir=C:/tmp -cp "%CP%" %VM% org.basex.BaseXServer %*) > and 2) call basexclient -c cmd.xml with the content above, I get an empty > testdb folder in basex/bin and a testdb folder containing newdoc in c:\tmp > (of course, c:\tmp existed before). > > Two more notes: > 1) While testing the script, I noticed that my initial description was a bit > imprecise: actually, the folder which is created in basex/bin is not named > from the database, but from the path='xxx' option given in the export > command (i.e. "testdb" for the example above, and not 'test'; unfortunately > both were identical in my initial tests). > > 2) Additionally I found out that the behavior is different when the database > is empty: in this case, the folder structure is still created in basex/bin, > but *not* in the user.dir path. I do not know what is intended for the > export of an empty database - creation of the (empty) export folder > structure, or no filesystem operations at all? > > Thanks for your help, > Greets > Simon
SG
Simon Görke3 Dec 2013 17:23 #
Hi Christian, As far as we can say from the file-related functionality we are actually using, your modifications in the 7.8beta work perfectly fine. Great.
Quoted text · Christian Grün · 1 line
> I remember some forum posting that discouraged the use of user.dir
I also found some threads which point to this direction, however the background and the implications are not fully clear to me (which also might be due to my limited java background). At least some of the posts also indicate that the issue can be addressed by consequently using getAbsoluteFile() (as you did if I got that right). If any problems occur with the current solution, using a dedicated system property for defining the absolute path to the file system might be another option. Thanks once again for your help. Best Simon
Quoted text · Christian Grün · 19 lines
-----Ursprüngliche Nachricht----- Von: Christian Grün [mailto:christian.gruen at gmail.com] Gesendet: Sonntag, 1. Dezember 2013 14:12 An: Simon Görke Cc: BaseX Betreff: Re: [basex-talk] user.dir and BaseX Add Command Hi Simon, The reason for the trouble was the following Java operations do different things if user.dir is changed: new File("X").mkdirs() new File("X").getAbsoluteFile().mkdirs() Ive rewritten our file operations such that they are always resolved against the absolute file path. I cant promise that everyone works fine now (I remember some forum posting that discouraged the use of user.dir, probably because of reasons like the one above), so Im interested in your feedback on the new snapshot [1]. Best, Christian [1] http://files.basex.org/releases/latest/

⚡Generated with XQuery