update_file#
- barecat.Barecat.update_file(old_item, new_item=None, *, data=None, fileobj=None, size=None, bufsize=shutil.COPY_BUFSIZE)[source]#
Update an existing file’s data and/or metadata, reusing space if new data fits.
If new data is smaller or equal to old data, writes in-place at the existing location, avoiding fragmentation. If new data is larger, writes at a new location (old location becomes a gap).
- Parameters:
old_item (Union[BarecatFileInfo, str]) – The existing file to update. Either a BarecatFileInfo (if user already looked it up) or a path string.
new_item (Union[BarecatFileInfo, str, None]) – Optional new metadata. If BarecatFileInfo, its metadata fields (path, mtime_ns, mode, uid, gid) are the new values. If string, it’s the new path (rename). If None, only data is updated.
data (Optional[bytes]) – New file content. Either data or fileobj must be provided.
fileobj – File-like object to read new data from.
size (Optional[int]) – Size of new data. Required for fileobj if writing in-place.
bufsize (int) – Buffer size for reading from fileobj.
- Raises:
FileNotFoundBarecatError – If file does not exist.
ValueError – If neither data nor fileobj provided, or both provided.