diff --git a/contrib/teamcity/build-configurations.py b/contrib/teamcity/build-configurations.py --- a/contrib/teamcity/build-configurations.py +++ b/contrib/teamcity/build-configurations.py @@ -234,7 +234,8 @@ continue # If there is a single file, destination is the new file path - if len(matches) == 1 and matches[0].is_file(): + if len(matches) == 1 and matches[0].is_file( + ) and dest != self.artifact_dir: # Create the parent directories as needed dest.parent.mkdir(parents=True, exist_ok=True) shutil.copy2(matches[0], dest) @@ -348,6 +349,12 @@ def run(self, args=[]): if self.artifact_dir.is_dir(): shutil.rmtree(self.artifact_dir) + if self.artifact_dir.is_file(): + # This is not expected, but clean it up anyway + os.remove(self.artifact_dir) + if self.artifact_dir.exists(): + raise FileExistsError( + "{} expected to not exist. Some unexpected file is located there instead.") self.artifact_dir.mkdir(exist_ok=True) self.configuration.create_build_steps(self.artifact_dir)