Skip to content

Cannot put if the server storage starts empty. #29

@fiendish

Description

@fiendish

def _find_object_for_path(self, path):
if not self.content_object:
return None

makes it impossible to create things starting from scratch using SFTPServer(content_object={}) because e.g. mkdir('test') invokes self._get_path_components('test') which returns ('', 'test') and then self._find_object_for_path('') returns None instead of the global storage object.

(the default content_object should be {} and not None too)

Fixed ContentProvider is

class FixedContentProvider(ContentProvider):  # fixes default content_object
    def __init__(self, content_object=None):
        self.content_object = content_object or {}

    def is_dir(self, path):  # fixes wrong mode attr on binary uploads
        return not isinstance(self.get(path), (bytes, str, int))

    def _find_object_for_path(self, path):  # fixes adding to empty storage
        if path == '':
            return self.content_object
        else:
            return super()._find_object_for_path(path)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions