From 4a992808e4bd3545799482746e169f03c3f0d533 Mon Sep 17 00:00:00 2001 From: John Truckenbrodt Date: Tue, 17 Sep 2024 15:47:02 +0200 Subject: [PATCH] [DEMHandler] only lock VRT if path is writable --- pyroSAR/auxdata.py | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/pyroSAR/auxdata.py b/pyroSAR/auxdata.py index e2c28801..a28ce3cf 100644 --- a/pyroSAR/auxdata.py +++ b/pyroSAR/auxdata.py @@ -536,16 +536,21 @@ def __buildvrt(tiles, vrtfile, pattern, vsi, extent, src_nodata=None, opts['VRTNodata'] = dst_nodata opts['outputBounds'] = (extent['xmin'], extent['ymin'], extent['xmax'], extent['ymax']) - with Lock(vrtfile, timeout=lock_timeout): - if not os.path.isfile(vrtfile): - gdalbuildvrt(src=locals, dst=vrtfile, **opts) - if dst_datatype is not None: - datatype = Dtype(dst_datatype).gdalstr - tree = etree.parse(source=vrtfile) - band = tree.find(path='VRTRasterBand') - band.attrib['dataType'] = datatype - tree.write(file=vrtfile, pretty_print=True, - xml_declaration=False, encoding='utf-8') + lock = None + if os.access(vrtfile, os.W_OK): + # lock only if writable, not e.g. vsimem + lock = Lock(vrtfile, timeout=lock_timeout) + if not os.path.isfile(vrtfile): + gdalbuildvrt(src=locals, dst=vrtfile, **opts) + if dst_datatype is not None: + datatype = Dtype(dst_datatype).gdalstr + tree = etree.parse(source=vrtfile) + band = tree.find(path='VRTRasterBand') + band.attrib['dataType'] = datatype + tree.write(file=vrtfile, pretty_print=True, + xml_declaration=False, encoding='utf-8') + if lock is not None: + lock.remove() def __commonextent(self, buffer=None): """