コード例 #1
0
ファイル: storage.py プロジェクト: HuiD/pikapika-py
    def save(self, name, content):
        if name is None:
            name = content.name

        full_name = self.path(name)
        full_name_content = self.path(content.name)

        # Ensure that two pathes really point to the same file
        if (_samefile(full_name, full_name_content)
                and os.path.isfile(full_name)
                and os.stat(full_name).st_size == content.size):

            return name
        else:
            return super(CustomFileSystemStorage, self).save(name, content)
コード例 #2
0
ファイル: storage.py プロジェクト: HuiD/pikapika-py
    def save(self, name, content):
        if name is None:
            name = content.name

        full_name = self.path(name)
        full_name_content = self.path(content.name)

        # Ensure that two pathes really point to the same file
        if (_samefile(full_name, full_name_content) and 
            os.path.isfile(full_name) and
            os.stat(full_name).st_size == content.size):

            return name
        else:
            return super(CustomFileSystemStorage, self).save(name, content)
コード例 #3
0
ファイル: storage.py プロジェクト: aristippe/pathagar
def file_symlink_safe(old_file_name, new_file_name, allow_overwrite=False):
    """
    Create a symbolic link to `old_file_name` from `new_file_name`.

    Might raise NotImplemented if the system does not support symbolic links,
    and IOError or other Exceptions thrown by os.symlink.

    :param old_file_name:
    :param new_file_name:
    :param allow_overwrite:
    :return:
    """
    # Make sure the system has support for symbolic links.
    # TODO: detect it with more precision, check for other platforms.
    if os.name != 'posix':
        raise NotImplemented('System %s does not support symbolic links' %
                             os.name)

    # There's no reason to move if we don't have to.
    if _samefile(old_file_name, new_file_name):
        return

    # Create the symbolic link.
    os.symlink(old_file_name, new_file_name)