aboutsummaryrefslogtreecommitdiff
path: root/src/MinioUploadManager.cs
blob: 8337438fd937e45f252d565f835e8a807b20f716 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
using System.Diagnostics.CodeAnalysis;
using System.Threading.Tasks;

using VNLib.Tools.Build.Executor.Model;

using static VNLib.Tools.Build.Executor.Constants.Utils;

namespace VNLib.Tools.Build.Executor
{
    internal class MinioUploadManager : IUploadManager
    {
        private readonly string _minioPath;

        private MinioUploadManager(string minioPath)
        {
            _minioPath = minioPath; 
        }

        public Task CleanAllAsync(string path)
        {
            throw new System.NotImplementedException();
        }

        public Task DeleteFileAsync(string filePath)
        {
            throw new System.NotImplementedException();
        }

        public async Task UploadDirectoryAsync(string path)
        {
            //Recursivley copy all files in the working directory
            string[] args = 
            {
                "cp",
                "--recursive",
                ".",
               _minioPath
            };

            //Set working dir to the supplied dir path, and run the command
            int result = await RunProcessAsync("mc", path, args);

            if(result != 0)
            {
                throw new BuildStepFailedException($"Failed to upload directory {path} with status code {result:x}");
            }
        }

        public Task UploadFileAsync(string filePath)
        {
            throw new System.NotImplementedException();
        }

        [return:NotNullIfNotNull(nameof(uploadPath))]
        public static IUploadManager? Create(string? uploadPath)
        {
            return string.IsNullOrWhiteSpace(uploadPath) ? null : new MinioUploadManager(uploadPath);
        }
    }
}