djblets.util.filesystem¶
Filesystem-related utilities.
- is_exe_in_path(name: str) bool ¶
Checks whether an executable is in the user’s search path.
This expects a name without any system-specific executable extension. It will append the proper extension as necessary. For example, use “myapp” and not “myapp.exe”.
This will return True if the app is in the path, or False otherwise.
- safe_join(base: str, *paths: str, path_mod: ~typing.Any = <module 'posixpath' (frozen)>, rel_to: ~typing.Optional[str] = None) str ¶
Safely join filesystem paths, ensuring the result is within a base path.
This will join paths and and ensure the resulting path doesn’t escape the base path, making it safer when including non-static path components.
The result is always an absolute path, unless
rel_to
is provided.The implementation is based on Django’s internal
django.utils._os.safe_join()
function, with additional functionality, optimizations, and typing.New in version 4.0.
- Parameters:
- Returns:
The absolute joined path.
- Return type:
- Raises:
django.core.exceptions.SuspiciousFileOperation – The resulting path was outside of the base path.