Question - how to interact with Windows OSFS paths?
Please see issue palewire/django-bakery#156. In one commit, I changed a couple places where that code uses os.path.join() for a path that will be validated by PyFilesystem2. However, there is still a validation issue with paths that start with C:/ and it is not clear to me how the abstraction is supposed to work.
The issue is that when the BUILD_DIR is set to a path such as "C:\Users\davisda4\workdir\build", then the path is not valid according to fs.path.validatepath. The error occurs when checking whether the path exists at https://github.com/palewire/django-bakery/blob/master/bakery/views/base.py#L62.
In this code, self.fs is an OSFS filesystem initialized from "osfs:///", which may not be valid on Windows.
PyFilesystem is always expecting paths with forward slashes, and you should not use fs.path with filesystem paths. In theory, the idea would be that you do:
import os
import fs
with fs.open_fs(os.getenv("BUILD_DIR")) as build_dir:
build_dir.makedirs("/the/dir/to/make")
So in your example:
def prep_directory(self, target_dir):
"""
Prepares a new directory to store the file at the provided path, if needed.
"""
dirname = path.dirname(target_dir)
if dirname:
with fs.open_fs(settings.BUILD_DIR) as build_dir:
if not build_dir.exists(dirname):
logger.debug("Creating directory at {}".format(build_dir.getsyspath(dirname)))
build_dir.makedirs(dirname)
@althonos Presumably that last line in your example should have been build_dir.makedirs(dirname) ?
Yes indeed, edited.