mkdir-parents.c revision aeb01e4ba09e5be7a642e98ab54c4ab05cdebd86
a8c5a86d183db25a57bf193c06b41e092ec2e151Timo Sirainen/* Copyright (c) 2003-2009 Dovecot authors, see the included COPYING file */
9f627b360ed38fdc54cb02ec5e67246c3f0d5b0fTimo Sirainenint mkdir_chown(const char *path, mode_t mode, uid_t uid, gid_t gid)
53dfcefa9440a49d703e49193819a79be99c9ba6Timo Sirainen /* EISDIR check is for BSD/OS which returns it if path
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen contains '/' at the end and it exists.
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen ENOSYS check is for NFS mount points. */
2e78f05b11df23ec2731afaf8f19d5b5240cb29fTimo Sirainen i_error("chown(%s, %ld, %ld) failed: %m", path,
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainenint mkdir_parents_chown(const char *path, mode_t mode, uid_t uid, gid_t gid)
660b99a7059824676b2b8d6f79b8e15d47df25a2Timo Sirainen const char *p;
9f627b360ed38fdc54cb02ec5e67246c3f0d5b0fTimo Sirainen /* doesn't exist, try recursively creating our parent dir */
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen ret = mkdir_parents_chown(t_strdup_until(path, p),
9f627b360ed38fdc54cb02ec5e67246c3f0d5b0fTimo Sirainen /* should work now */
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainenint mkdir_parents(const char *path, mode_t mode)
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen return mkdir_parents_chown(path, mode, (uid_t)-1, (gid_t)-1);