dba/files
library moduleR
Summary
Change directory.
- Authors
- Christian Grün, BaseX Team 2005-23, BSD License
Imports
This module is imported by 0 modules. It imports 1 modules.
Variables
Functions
4.1 dba:dir-change
Arities: #1R
dba:dir-change
(
$dir
as
xs:string
) as
element(rest:response)
- dir
as
xs:string
directory
element(rest:response)
redirection
Invoked by 0 functions from 0 modules
Annotations (2)
%rest:path | ('/dba/dir-change') |
%rest:query-param | ('dir','{$dir}') |
Source ( 22 lines)
function dba:dir-change(
$dir as xs:string
) as element(rest:response) {
try {
let $sep := file:dir-separator()
let $path := file:path-to-native(if(contains($dir, $sep)) then (
$dir
) else (
config:directory() || $dir || $sep)
)
return (
(: ensure that the directory can be accessed :)
prof:void(file:list($path)),
config:directory($path),
config:query('')
),
web:redirect($dba:CAT)
} catch file:io-error {
web:redirect($dba:CAT, map { 'error': $err:description })
}
}
Namespaces
The following namespaces are defined:
Prefix | Uri |
---|---|
config | dba/config |
dba | dba/files 2 3 4 5 6 7 8 |
err | http://www.w3.org/2005/xqt-errors |
file | http://expath.org/ns/file |
prof | http://basex.org/modules/prof |
rest | http://exquery.org/ns/restxq |
web | http://basex.org/modules/web |
xs | http://www.w3.org/2001/XMLSchema |
Source Code
(:~
: Change directory.
:
: @author Christian Grün, BaseX Team 2005-23, BSD License
:)
module namespace dba = 'dba/files';
import module namespace config = 'dba/config' at '../lib/config.xqm';
(:~ Top category :)
declare variable $dba:CAT := 'files';
(:~
: Changes the directory.
: @param $dir directory
: @return redirection
:)
declare
%rest:path('/dba/dir-change')
%rest:query-param('dir', '{$dir}')
function dba:dir-change(
$dir as xs:string
) as element(rest:response) {
try {
let $sep := file:dir-separator()
let $path := file:path-to-native(if(contains($dir, $sep)) then (
$dir
) else (
config:directory() || $dir || $sep)
)
return (
(: ensure that the directory can be accessed :)
prof:void(file:list($path)),
config:directory($path),
config:query('')
),
web:redirect($dba:CAT)
} catch file:io-error {
web:redirect($dba:CAT, map { 'error': $err:description })
}
};