I guess there isn't much savings in this:

    os.remove(filepath)
    cwd = os.getcwd()
    try:
        common_base = os.path.commonprefix(
            self.config.source_directory,
            path
        )
        os.chdir(common_base)
        os.removedirs(path.replace(common_base, ''))
    finally:
        os.chdir(cwd)