Example #1
0
    def rename_generic_file_to(self, generic_file, initial_filepath,
                               destination_filepath):
        # There is no need to verify if the destination directory exists, and if there is not already a file with the same name,
        # as FUSE will automatically verify those conditions before calling our implementation of file moving.

        # First we decrease the number of nlink in the directory above (even if we might stay in the same repository
        # at the end, that's not a big deal)
        initial_directory_id = GenericFile.get_directory_id(
            filepath=initial_filepath)
        self.add_nlink_directory(directory_id=initial_directory_id, value=-1)

        # We rename it
        destination_directory_id = GenericFile.get_directory_id(
            filepath=destination_filepath)
        dest_filename = destination_filepath.split('/')[-1]
        Mongo.cache.find_one_and_update(
            self.files_coll, {'_id': generic_file._id}, {
                '$set': {
                    'directory_id': destination_directory_id,
                    'filename': dest_filename
                }
            })

        # We increase the number of nlink in the final directory
        self.add_nlink_directory(directory_id=destination_directory_id,
                                 value=-1)
Example #2
0
    def rename_generic_file_to(self, generic_file, initial_filepath,
                               destination_filepath):
        # There is no need to verify if the destination directory exists, and if there is not already a file with the same name,
        # as FUSE will automatically verify those conditions before calling our implementation of file moving.

        destination_directory = GenericFile.get_directory(
            filepath=destination_filepath)
        if not GenericFile.has_user_access_right(destination_directory,
                                                 GenericFile.WRITE_RIGHTS):
            print('No rights to write on folder ' +
                  destination_directory.filename)
            raise FuseOSError(errno.EACCES)

        # First we decrease the number of nlink in the directory above (even if we might stay in the same repository
        # at the end, that's not a big deal)
        initial_directory_id = GenericFile.get_directory_id(
            filepath=initial_filepath)
        self.add_nlink_directory(directory_id=initial_directory_id, value=-1)

        # We rename it
        destination_directory_id = destination_directory._id
        dest_filename = destination_filepath.split('/')[-1]
        Mongo.cache.find_one_and_update(
            self.files_coll, {'_id': generic_file._id}, {
                '$set': {
                    'directory_id': destination_directory_id,
                    'filename': dest_filename
                }
            })

        # We increase the number of nlink in the final directory
        self.add_nlink_directory(directory_id=destination_directory_id,
                                 value=-1)
    def test_get_directory_id(self):
        self.utils.insert_directory()
        self.utils.insert_directory_file()

        directory_id = GenericFile.get_directory_id(
            filepath=self.utils.directory_file.filepath)
        self.assertEqual(directory_id, self.utils.directory_file.directory_id)