dba/files
library moduleR
Summary
Delete files.
- Tags
Author: Christian Grün, BaseX Team 2005-21, BSD License
__source : files/file-delete.xqm
Imports
This module is imported by 0 modules. It imports 2 modules.
Variables
Functions
4.1 dba:file-delete
Arities: dba:file-delete#1R
dba:file-delete
(
$names
as
xs:string*
)
as
element(rest:response)
- names
as
xs:string*
names of files
element(rest:response)
redirection
Invokes 4 functions from 4 modules
- config:directory#0
- util:info#3
- {http://basex.org/modules/web}redirect#2
- {http://expath.org/ns/file}delete#1
Invoked by 0 functions from 0 modules
Annotations
%rest:GET | () |
%rest:path | ('/dba/file-delete') |
%rest:query-param | ('name','{$names}') |
Source ( 13 lines)
function dba:file-delete(
$names as xs:string*
) as element(rest:response) {
try {
(: delete all files, ignore reference to parent directory :)
for $name in $names
where $name != '..'
return file:delete(config:directory() || $name),
web:redirect($dba:CAT, map { 'info': util:info($names, 'file', 'deleted') })
} catch * {
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 |
rest | http://exquery.org/ns/restxq |
util | dba/util |
Source Code
(:~
: Delete files.
:
: @author Christian Grün, BaseX Team 2005-21, BSD License
:)
module namespace dba = 'dba/files';
import module namespace config = 'dba/config' at '../lib/config.xqm';
import module namespace util = 'dba/util' at '../lib/util.xqm';
(:~ Top category :)
declare variable $dba:CAT := 'files';
(:~
: Deletes files.
: @param $names names of files
: @return redirection
:)
declare
%rest:GET
%rest:path('/dba/file-delete')
%rest:query-param('name', '{$names}')
function dba:file-delete(
$names as xs:string*
) as element(rest:response) {
try {
(: delete all files, ignore reference to parent directory :)
for $name in $names
where $name != '..'
return file:delete(config:directory() || $name),
web:redirect($dba:CAT, map { 'info': util:info($names, 'file', 'deleted') })
} catch * {
web:redirect($dba:CAT, map { 'error': $err:description })
}
};