Skip to content

Commit 5727ad5

Browse files
Updated to first try to delete the file. Then to try and create the directory if necessary. Then try to add the new file.
1 parent a16638f commit 5727ad5

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

Skyline.DataMiner.CICD.Tools.GitHubToCatalogYaml/CatalogManager.cs

+5-7
Original file line numberDiff line numberDiff line change
@@ -316,17 +316,15 @@ private static string InferArtifactContentType(string keyword)
316316
private void SaveFile(CatalogYaml catalogYaml, ISerializer serializer, string outputPath)
317317
{
318318
logger.LogDebug($"Serializing and saving the updated catalog.yml file with path: {outputPath}.");
319-
319+
// Delete the file if it already exists. Overwriting an existing file is not allowed in GitHub.
320+
fs.File.DeleteFile(outputPath);
321+
Thread.Sleep(500);
320322
var updatedYaml = serializer.Serialize(catalogYaml);
321-
fs.Directory.CreateDirectory(outputPath);
322-
var parentDir = fs.File.GetParentDirectory(outputPath);
323323

324-
// Required by GitHub to change existing files.
324+
var parentDir = fs.Path.GetDirectoryName(outputPath);
325+
fs.Directory.CreateDirectory(parentDir);
325326
fs.Directory.TryAllowWritesOnDirectory(parentDir);
326327

327-
// Delete the file if it already exists. Overwriting an existing file is not allowed in GitHub.
328-
fs.File.DeleteFile(outputPath);
329-
Thread.Sleep(500);
330328
fs.File.WriteAllText(outputPath, updatedYaml);
331329
}
332330
}

0 commit comments

Comments
 (0)