5
5
import os .path
6
6
import re
7
7
import shutil
8
+ import stat
8
9
import sys
9
10
from io import open # pylint: disable=redefined-builtin
10
11
from typing import Dict , List , MutableMapping , Optional
@@ -170,18 +171,36 @@ def add_volumes(self, pathmapper, runtime, stage_output):
170
171
containertgt = container_outdir + vol .target [len (host_outdir ):]
171
172
else :
172
173
containertgt = vol .target
173
- if vol .target .startswith (container_outdir + "/" ):
174
- host_outdir_tgt = os .path .join (
175
- host_outdir , vol .target [len (container_outdir ) + 1 :])
176
174
if vol .type in ("File" , "Directory" ):
177
-
178
- if not vol .resolved .startswith ("_:" ):
175
+ if vol .target .startswith (container_outdir + "/" ):
176
+ # workaround for lack of overlapping mounts in Singularity
177
+ # revert to daa923d5b0be3819b6ed0e6440e7193e65141052
178
+ # once https://github.com/sylabs/singularity/issues/1607
179
+ # is fixed
180
+ target = os .path .join (
181
+ self .outdir , os .path .basename (vol .target ))
182
+ os .link (os .path .realpath (vol .resolved ), target )
183
+ os .chmod (target , stat .S_IRUSR )
184
+ elif not vol .resolved .startswith ("_:" ):
179
185
runtime .append (u"--bind" )
180
186
runtime .append ("{}:{}:ro" .format (
181
187
docker_windows_path_adjust (vol .resolved ),
182
188
docker_windows_path_adjust (containertgt )))
183
189
elif vol .type == "WritableFile" :
184
- if self .inplace_update :
190
+ if containertgt .startswith (container_outdir + "/" ):
191
+ # workaround for lack of overlapping mounts in Singularity
192
+ # revert to daa923d5b0be3819b6ed0e6440e7193e65141052
193
+ # once https://github.com/sylabs/singularity/issues/1607
194
+ # is fixed
195
+ target = os .path .join (
196
+ self .outdir , os .path .basename (containertgt ))
197
+ if self .inplace_update :
198
+ os .link (os .path .realpath (vol .resolved ), target )
199
+ os .chmod (target , stat .S_IRUSR | stat .S_IWUSR )
200
+ else :
201
+ shutil .copy (vol .resolved , target )
202
+ ensure_writable (target )
203
+ elif self .inplace_update :
185
204
runtime .append (u"--bind" )
186
205
runtime .append (u"{}:{}:rw" .format (
187
206
docker_windows_path_adjust (vol .resolved ),
@@ -193,7 +212,19 @@ def add_volumes(self, pathmapper, runtime, stage_output):
193
212
if vol .resolved .startswith ("_:" ) and host_outdir_tgt :
194
213
os .makedirs (host_outdir_tgt , 0o0755 )
195
214
else :
196
- if self .inplace_update :
215
+ if containertgt .startswith (container_outdir + "/" ):
216
+ # workaround for lack of overlapping mounts in Singularity
217
+ # revert to daa923d5b0be3819b6ed0e6440e7193e65141052
218
+ # once https://github.com/sylabs/singularity/issues/1607
219
+ # is fixed
220
+ target = os .path .join (
221
+ self .outdir , os .path .basename (containertgt ))
222
+ if self .inplace_update :
223
+ os .link (os .path .realpath (vol .resolved ), target )
224
+ os .chmod (target , stat .S_IRUSR | stat .S_IWUSR )
225
+ else :
226
+ shutil .copytree (vol .resolved , target )
227
+ elif self .inplace_update :
197
228
runtime .append (u"--bind" )
198
229
runtime .append (u"{}:{}:rw" .format (
199
230
docker_windows_path_adjust (vol .resolved ),
0 commit comments