fsutil
Small filesystem helpers shared by the launch logic and the file manager.
attributelogger= logging.getLogger(__name__)funcresolve_within(base, path) -> strReturn the real path of path after checking that it lies inside base.
Both paths are resolved with os.path.realpath, so neither .. segments
nor symlinks can be used to escape base. Trailing components that do not
exist yet are allowed, which makes the helper usable for paths about to be
created.
parambasestrTrusted directory the result must stay inside.
parampathstrCandidate path, usually built from client-supplied names.
Returns
strThe resolved absolute path.
funcsafe_join(base, *parts) -> strJoin parts onto base and return the resolved path inside base.
parambasestrTrusted directory.
parampartsstr= ()Returns
strThe resolved absolute path.
funcsafe_copytree(src, dst, symlinks=True) -> NoneCopy a directory tree, tolerating dangling symlinks.
paramsrcstrSource directory.
paramdststrDestination directory (must not exist).
paramsymlinksbool= TrueCopy symlinks as symlinks instead of following them.
Returns
Nonefuncsafe_rmtree(path) -> NoneRemove a directory tree, translating permission errors to HTTP 403.
parampathstrDirectory to remove.
Returns
Nonefuncunique_filename(directory, filename) -> strReturn filename or a name-N.ext variant that does not exist yet.
paramdirectorystrDirectory the file will be placed in.
paramfilenamestrDesired file name.
Returns
strA file name that is free inside directory.
funcsanitize_for_filename(name) -> strTurn an arbitrary display name into a safe directory name.
paramnamestrDisplay name such as an application name.
Returns
strLower-case ASCII letters, digits and dashes, at most 50 characters,