diff --git a/src/PollinationSDK/Helper/Helper.cs b/src/PollinationSDK/Helper/Helper.cs
index 92e76c1f..55420412 100644
--- a/src/PollinationSDK/Helper/Helper.cs
+++ b/src/PollinationSDK/Helper/Helper.cs
@@ -234,7 +234,7 @@ public static string CheckPathForDir(string savedFolderOrFilePath)
{
var p = savedFolderOrFilePath;
// check folder
- if (!Path.HasExtension(p))
+ if (IsDirectory(p))
{
var tempDir = new DirectoryInfo(p);
var subItems = tempDir.GetFileSystemInfos("*", SearchOption.TopDirectoryOnly);
@@ -278,6 +278,13 @@ public static bool GetRecipeFromRecipeSourceURL(string recipeSource, out string
return true;
}
+ public static bool IsDirectory(string path)
+ {
+ FileAttributes attr = File.GetAttributes(path);
+ var isDir = attr.HasFlag(FileAttributes.Directory);
+ return isDir;
+ }
+
///
/// Download all cloud reference assets (file or folder) from a project folder
@@ -306,13 +313,13 @@ public static async Task> DownloadAssetsAsync(string p
var projName = proj[1];
// check folder assets
- var gp = assets.GroupBy(_ => Path.HasExtension(_.RelativePath));
- var fileAssets = gp.FirstOrDefault(_ => _.Key == true)?.Select(_ => _)?.ToList() ?? new List();
- var folderAssets = gp.FirstOrDefault(_ => _.Key == false)?.Select(_ => _.RelativePath)?.ToList();
+ var gp = assets.GroupBy(_ => _.IsFolder);
+ var fileAssets = gp.FirstOrDefault(_ => _.Key == false)?.Select(_ => _)?.ToList() ?? new List();
+ var folderAssets = gp.FirstOrDefault(_ => _.Key == true)?.Select(_ => _.RelativePath)?.ToList();
if (folderAssets != null && folderAssets.Any())
{
var allFiles = await GetAllFilesAsync(api, projOwner, projName, folderAssets, saveAsDir);
- var cloudRefs = allFiles.Select(_ => new CloudReferenceAsset(projOwner, projName, _.Key));
+ var cloudRefs = allFiles.Select(_ => new CloudReferenceAsset(projOwner, projName, _.Key, _.FileType));
fileAssets.AddRange(cloudRefs);
}
@@ -380,15 +387,15 @@ public static async Task> DownloadAssetsAsync(string p
var projName = proj[1];
// check folder assets
- var gp = assets.GroupBy(_ => Path.HasExtension(_.RelativePath));
- var fileAssets = gp.FirstOrDefault(_ => _.Key == true)?.Select(_ => _)?.ToList() ?? new List();
- var folderAssets = gp.FirstOrDefault(_ => _.Key == false)?.Select(_ => _.RelativePath)?.ToList();
+ var gp = assets.GroupBy(_ => _.IsFolder);
+ var fileAssets = gp.FirstOrDefault(_ => _.Key == false)?.Select(_ => _)?.ToList() ?? new List();
+ var folderAssets = gp.FirstOrDefault(_ => _.Key == true)?.Select(_ => _.RelativePath)?.ToList();
var api = new PollinationSDK.Api.JobsApi();
if (folderAssets != null && folderAssets.Any())
{
var allFiles = await GetAllFilesAsync(api, projOwner, projName, jobId, folderAssets, saveAsDir);
- var cloudRefs = allFiles.Select(_ => new CloudReferenceAsset(projOwner, projName, jobId, _.Key));
+ var cloudRefs = allFiles.Select(_ => new CloudReferenceAsset(projOwner, projName, jobId, _.Key, _.FileType));
fileAssets.AddRange(cloudRefs);
}
@@ -495,12 +502,6 @@ public static async Task DownloadArtifactAsync(ArtifactsApi api, string
if (fileRelativePath.StartsWith("/"))
fileRelativePath = fileRelativePath.Substring(1);
- if (!Path.HasExtension(fileRelativePath)) // dir
- {
- var msg = $"Cannot download the following folder directly: {fileRelativePath}";
- throw new ArgumentException(msg);
- }
-
var url = (await api.DownloadArtifactAsync(projOwner, projName, fileRelativePath))?.ToString();
Helper.Logger.Information($"DownloadArtifactAsync: downloading {fileRelativePath} from \n -{url}\n");
@@ -519,12 +520,6 @@ public static async Task DownloadArtifactAsync(JobsApi api, string projO
if (fileRelativePath.StartsWith("/"))
fileRelativePath = fileRelativePath.Substring(1);
- if (!Path.HasExtension(fileRelativePath)) // dir
- {
- var msg = $"Cannot download the following folder directly: {fileRelativePath}";
- throw new ArgumentException(msg);
- }
-
var url = (await api.DownloadJobArtifactAsync(projOwner, projName, jobId, fileRelativePath, cancelToken))?.ToString();
Helper.Logger.Information($"DownloadJobArtifactAsync: downloading {fileRelativePath} from \n -{url}\n");
diff --git a/src/PollinationSDK/Wrapper/AssetBase.cs b/src/PollinationSDK/Wrapper/AssetBase.cs
index a9ded99e..a3cb8916 100644
--- a/src/PollinationSDK/Wrapper/AssetBase.cs
+++ b/src/PollinationSDK/Wrapper/AssetBase.cs
@@ -34,6 +34,14 @@ public abstract class AssetBase
///
public string RelativePath { get; protected set; }
+ [JsonProperty]
+ ///
+ /// folder or file
+ ///
+ public string PathType { get; protected set; } = "file";
+ public bool IsFolder => this.PathType == "folder";
+ public bool IsFile => this.PathType == "file";
+
[JsonProperty]
public string LocalPath { get; set; }
diff --git a/src/PollinationSDK/Wrapper/CloudReferenceAsset.cs b/src/PollinationSDK/Wrapper/CloudReferenceAsset.cs
index 66575c9a..05e8e871 100644
--- a/src/PollinationSDK/Wrapper/CloudReferenceAsset.cs
+++ b/src/PollinationSDK/Wrapper/CloudReferenceAsset.cs
@@ -19,13 +19,13 @@ public CloudReferenceAsset()
}
- public CloudReferenceAsset(string projOwner, string projName, string assetPath)
+ public CloudReferenceAsset(string projOwner, string projName, string assetPath, string pathType = "file")
{
// get name
this.Name = System.IO.Path.GetFileNameWithoutExtension(assetPath);
-
// check path type
+ this.PathType = pathType;
this.RelativePath = assetPath;
this.ProjectSlug = $"{projOwner}/{projName}";
@@ -34,13 +34,14 @@ public CloudReferenceAsset(string projOwner, string projName, string assetPath)
this.RunSource = $"CLOUD:{ProjectSlug}/{_cloudReferenceAssetKey}";
}
- public CloudReferenceAsset(string projOwner, string projName, string jobID, string assetPath)
+ public CloudReferenceAsset(string projOwner, string projName, string jobID, string assetPath, string pathType)
{
// get name
this.Name = System.IO.Path.GetFileNameWithoutExtension(assetPath);
// check path type
+ this.PathType = pathType;
this.RelativePath = assetPath;
this.ProjectSlug = $"{projOwner}/{projName}";
diff --git a/src/PollinationSDK/Wrapper/LocalRunArguments.cs b/src/PollinationSDK/Wrapper/LocalRunArguments.cs
index 3bba5437..395a26af 100644
--- a/src/PollinationSDK/Wrapper/LocalRunArguments.cs
+++ b/src/PollinationSDK/Wrapper/LocalRunArguments.cs
@@ -52,7 +52,7 @@ public LocalRunArguments(List> arguments)
//copy to folder
var tempPath = (p.Source.Obj as PollinationSDK.ProjectFolder).Path;
var pathName = string.Empty;
- if (System.IO.Path.HasExtension(tempPath)) // file type
+ if (!Helper.IsDirectory(tempPath)) // file type
{
if (!File.Exists(tempPath))
throw new ArgumentException($"Failed to find path argument {tempPath}");
diff --git a/src/PollinationSDK/Wrapper/RunInfo.cs b/src/PollinationSDK/Wrapper/RunInfo.cs
index 07f73b81..60ad0e31 100644
--- a/src/PollinationSDK/Wrapper/RunInfo.cs
+++ b/src/PollinationSDK/Wrapper/RunInfo.cs
@@ -363,7 +363,7 @@ public List LoadLocalRunAssets(List runAssets, strin
}
else if (dup is RunOutputAsset output)
{
- var isFile = Path.HasExtension(output.RelativePath);
+ var isFile = !Helper.IsDirectory(output.RelativePath);
var relativeOutPath = output.RelativePath.Replace("/", @"\");
relativeOutPath = relativeOutPath.StartsWith(@"\") ? relativeOutPath : $@"\{relativeOutPath}";
if (isFile)
@@ -396,7 +396,7 @@ public List LoadLocalRunAssets(List runAssets, strin
Directory.CreateDirectory(newRoot);
// file type
- if (Path.HasExtension(newPath))
+ if (!Helper.IsDirectory(newPath))
{
File.Copy(dup.LocalPath, newPath, true);
}