From: Craig B. <cra...@ma...> - 2023-06-06 19:41:37
|
> On Jun 6, 2023, at 2:04 PM, Nicolas Souchon <sou...@gm...> wrote: > > Dear All, > > I'm new to eXist-db and can't figure out how to change ownership of a folder and all the folders and files it contains at once from eXide. > > I know how to change ownership of one folder or file at a time but how can I change ownership of a large number of folders/files at once? Knowing that changing the ownership of the folder does not change the ownership of the items it contains. > > To be more clear, my application is owned by user A but one of the folders composing it is owned by user B and user A cannot access the contents of this folder, so I would like to change the ownership of the folder and its content from user B to user A. > > Thank you in advance for your help. I had to do this the other day and couldn't find a straightforward way. I ended up writing the following. Be sure to substitute your own root path and the desired owner, group and permissions. xquery version "3.1"; import module namespace dbutil="http://exist-db.org/xquery/dbutil"; import module namespace console="http://exist-db.org/xquery/console"; declare function local:setperm($path as xs:string) { let $x := sm:chown($path, 'owner') let $x := sm:chgrp($path, 'group') let $x := sm:chmod($path, 'rwxrwxr--') let $x := console:log('Ownership and permissions set on ' || $path) return $x }; let $root := '/db/apps/somepath' return dbutil:scan(xs:anyURI($root), function($col, $path) { let $x := local:setperm(($path, $col)[1]) return $x }) ________________________________________ Craig A. Berry "... getting out of a sonnet is much more difficult than getting in." Brad Leithauser |