123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263(******************************************************************************)(* ocaml-fileutils: files and filenames common operations *)(* *)(* Copyright (C) 2003-2014, Sylvain Le Gall *)(* *)(* This library is free software; you can redistribute it and/or modify it *)(* under the terms of the GNU Lesser General Public License as published by *)(* the Free Software Foundation; either version 2.1 of the License, or (at *)(* your option) any later version, with the OCaml static compilation *)(* exception. *)(* *)(* This library is distributed in the hope that it will be useful, but *)(* WITHOUT ANY WARRANTY; without even the implied warranty of *)(* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the file *)(* COPYING for more details. *)(* *)(* You should have received a copy of the GNU Lesser General Public License *)(* along with this library; if not, write to the Free Software Foundation, *)(* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *)(******************************************************************************)openFileUtilTypesopenFileUtilMiscopenFileUtilPermissionopenFileUtilSTATopenFileUtilLSopenFileUtilUMASKexceptionChmodErrorofstringtypechmod_error=[`Excofexn]letchmod?(error=funstr_->raise(ChmodErrorstr))?(recurse=false)modelst=let_,handle_exception=handle_error_gen"chmod"error(function#exc->"")inletrecchmod_onefn=letst=statfninifst.kind=Dir&&recursethenbeginList.iterchmod_one(lsfn)end;ifnotst.is_linkthenbeginletint_perm=matchmodewith|`Octali->i|`Symbolict->FileUtilMode.apply~is_dir:(st.kind=Dir)~umask:(umask(`Octal(funi->i)))(int_of_permissionst.permission)tinifint_perm<>int_of_permissionst.permissionthentryUnix.chmodfnint_permwithe->handle_exception~fatal:trueeendinList.iterchmod_onelst