16
16
# See the License for the specific language governing permissions and
17
17
# limitations under the License.
18
18
"""Utilities for renku service controllers."""
19
+ import shutil
20
+
19
21
from renku .command .clone import project_clone_command
20
22
from renku .core .util .contexts import renku_project_context
21
23
from renku .ui .service .cache .models .project import Project
@@ -31,7 +33,9 @@ def user_project_clone(cache, user_data, project_data):
31
33
32
34
user = cache .ensure_user (user_data )
33
35
project = cache .make_project (user , project_data , persist = False )
34
- project .abs_path .mkdir (parents = True , exist_ok = True )
36
+
37
+ # NOTE: Create parent dir so lock file can be created.
38
+ project .abs_path .parent .mkdir (parents = True , exist_ok = True )
35
39
36
40
with project .write_lock (), renku_project_context (project .abs_path , check_git_path = False ):
37
41
git_url = project_data .get ("git_url" )
@@ -51,6 +55,12 @@ def user_project_clone(cache, user_data, project_data):
51
55
service_log .debug (f"project already cloned, skipping clone: { git_url } " )
52
56
return found_project
53
57
58
+ if project .abs_path .exists ():
59
+ # NOTE: Remove dir since a previous clone might have failed somewhere in the middle.
60
+ shutil .rmtree (str (project .abs_path ))
61
+
62
+ project .abs_path .mkdir (parents = True , exist_ok = True )
63
+
54
64
repo , project .initialized = (
55
65
project_clone_command ()
56
66
.build ()
0 commit comments