util::Error RemoveDirectory(const acl::User& user, const VirtualPath& path) { util::Error e(PP::DirAllowed<PP::Delete>(user, path)); if (!e) return e; try { util::path::DirContainer dirCont(MakeReal(path).ToString()); for (auto& name : dirCont) { if (name[0] != '.') return util::Error::Failure(ENOTEMPTY); util::path::Status status((MakeReal(path) / name).ToString()); if (status.IsDirectory() || !status.IsWriteable()) return util::Error::Failure(ENOTEMPTY); } for (auto& name : dirCont) { RealPath entryPath(MakeReal(path) / name); if (unlink(entryPath.CString()) < 0) return util::Error::Failure(errno); } } catch (const util::SystemError& e) { return util::Error::Failure(e.Errno()); } return RemoveDirectory(MakeReal(path)); }
util::Error CreateDirectory(const acl::User& user, const VirtualPath& path) { util::Error e(PP::DirAllowed<PP::Makedir>(user, path)); if (!e) return e; e = CreateDirectory(MakeReal(path)); if (e) SetOwner(MakeReal(path), Owner(user.ID(), user.PrimaryGID())); return e; }
void DirEnumerator::Readdir(const acl::User& user, const fs::VirtualPath& path, bool loadOwners) { this->user = &user; this->path = MakeReal(path); this->loadOwners = loadOwners; Readdir(); }
DirEnumerator::DirEnumerator(const acl::User& user, const fs::VirtualPath& path, bool loadOwners) : user(&user), path(MakeReal(path)), totalBytes(0), loadOwners(loadOwners) { Readdir(); }
inline void MakeReal( DistMatrix<T,U,V>& A ) { #ifndef RELEASE PushCallStack("MakeReal"); #endif MakeReal( A.LocalMatrix() ); #ifndef RELEASE PopCallStack(); #endif }
util::Error ChangeDirectory(const acl::User& user, const VirtualPath& path) { util::Error e(PP::DirAllowed<PP::View>(user, path)); if (!e) return e; try { util::path::Status stat(MakeReal(path).ToString()); if (!stat.IsDirectory()) return util::Error::Failure(ENOTDIR); if (!stat.IsExecutable()) return util::Error::Failure(EACCES); } catch (const util::SystemError& e) { return util::Error::Failure(e.Errno()); } SetWorkDirectory(path); return util::Error::Success(); }
util::Error RemoveDirectory(const RealPath& path) { if (rmdir(MakeReal(path).CString()) < 0) return util::Error::Failure(errno); return util::Error::Success(); }
util::Error CreateDirectory(const RealPath& path) { if (mkdir(MakeReal(path).CString(), 0777) < 0) return util::Error::Failure(errno); return util::Error::Success(); }