Skip to content

Commit

Permalink
Implement truncate plugin callback (#1413)
Browse files Browse the repository at this point in the history
* Implement truncate plugin callback

* Update change log
  • Loading branch information
sgillies authored Jul 15, 2024
1 parent cbcbc76 commit d37994a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
7 changes: 7 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ Changes

All issue numbers are relative to https://github.com/Toblerity/Fiona/issues.

1.10.0rc1 (TBD)
---------------

Bug fixes:

- The truncate VSI plugin callback has been implemented (#1413).

1.10b2 (2024-07-10)
-------------------

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ dockertestimage:
docker build --target gdal --build-arg GDAL=$(GDAL) --build-arg PYTHON_VERSION=$(PYTHON_VERSION) -t fiona:$(GDAL)-py$(PYTHON_VERSION) .

dockertest: dockertestimage
docker run -it -v $(shell pwd):/app -v /tmp:/tmp --env AWS_ACCESS_KEY_ID --env AWS_SECRET_ACCESS_KEY --entrypoint=/bin/bash fiona:$(GDAL)-py$(PYTHON_VERSION) -c '/venv/bin/python -m pip install tiledb && /venv/bin/python -m pip install -vvv --editable .[all] --no-build-isolation && /venv/bin/python -B -m pytest -m "not wheel" --cov fiona --cov-report term-missing $(OPTS)'
docker run -it -v $(shell pwd):/app -v /tmp:/tmp --env AWS_ACCESS_KEY_ID --env AWS_SECRET_ACCESS_KEY --entrypoint=/bin/bash fiona:$(GDAL)-py$(PYTHON_VERSION) -c '/venv/bin/python -m pip install -vvv --editable .[all] --no-build-isolation && /venv/bin/python -B -m pytest -m "not wheel" --cov fiona --cov-report term-missing $(OPTS)'

dockershell: dockertestimage
docker run -it -v $(shell pwd):/app --env AWS_ACCESS_KEY_ID --env AWS_SECRET_ACCESS_KEY --entrypoint=/bin/bash fiona:$(GDAL)-py$(PYTHON_VERSION) -c '/venv/bin/python -m pip install --editable . --no-build-isolation && /bin/bash'
Expand Down
14 changes: 13 additions & 1 deletion fiona/_vsiopener.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,8 @@ cdef size_t pyopener_write(void *pFile, void *pBuffer, size_t nSize, size_t nCou
"Writing data: file_obj=%r, buff_view=%r, buffer_len=%r",
file_obj,
buff_view,
buffer_len)
buffer_len
)
try:
num = file_obj.write(buff_view)
except TypeError:
Expand All @@ -306,6 +307,16 @@ cdef int pyopener_flush(void *pFile) with gil:
return 1


cdef int pyopener_truncate(void *pFile, vsi_l_offset size) with gil:
cdef object file_obj = <object>pFile
log.debug("Truncating: file_obj=%r, size=%r", file_obj, size)
try:
file_obj.truncate(size)
return 0
except AttributeError:
return 1


cdef int pyopener_close(void *pFile) with gil:
cdef object file_obj = <object>pFile
log.debug("Closing: file_obj=%r", file_obj)
Expand Down Expand Up @@ -373,6 +384,7 @@ def _opener_registration(urlpath, obj):
callbacks_struct.read = <VSIFilesystemPluginReadCallback>pyopener_read
callbacks_struct.write = <VSIFilesystemPluginWriteCallback>pyopener_write
callbacks_struct.flush = <VSIFilesystemPluginFlushCallback>pyopener_flush
callbacks_struct.truncate = <VSIFilesystemPluginTruncateCallback>pyopener_truncate
callbacks_struct.close = <VSIFilesystemPluginCloseCallback>pyopener_close
callbacks_struct.read_dir = <VSIFilesystemPluginReadDirCallback>pyopener_read_dir
callbacks_struct.stat = <VSIFilesystemPluginStatCallback>pyopener_stat
Expand Down

0 comments on commit d37994a

Please sign in to comment.