I'm adding a list of tags to xattrs with:
def write_dolphin_xattr(parent_folder: str, metadata: Dict, tags: List[str], filetypes: List[str] = FILETYPES) -> None:
stars = metadata['score']
comment = metadata['comment']
for filetype in filetypes:
filepath = get_filepath(parent_folder, filetype)
tags = ",".join(tags)
xattr.setxattr(filepath, 'user.xdg.tags', tags.encode('utf-8'))
xattr.setxattr(filepath, 'user.xdg.comment', comment.encode('utf-8'))
xattr.setxattr(filepath, 'user.baloo.rating', stars.encode('utf-8'))
Sometimes I get the error OSError: [Errno 28] No space left on device.
How do I add tags until I get the error instead of trying to add all tags at the same time and not being able to add any of them?
The xattr size depends on the filesystem: https://man7.org/linux/man-pages/man7/xattr.7.html
I think the most efficient way would be a binary search for the largest list of tags that doesn't give an error.