Skip to content

Commit

Permalink
I think this works...
Browse files Browse the repository at this point in the history
  • Loading branch information
linus-berg committed Sep 29, 2024
1 parent b44ce31 commit 5ca8baa
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 16 deletions.
2 changes: 1 addition & 1 deletion ACM.Kernel/FileSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public string GetArtifactPath(string module, string uri_str) {
}

public async Task<long> GetFileSize(string filepath) {
FileSpec spec = await storage_backend_.GetFileInfoAsync(filepath);
FileSpec spec = await storage_backend_.GetFileInfoAsync(filepath) ?? throw new InvalidOperationException();
return spec.size;
}

Expand Down
7 changes: 4 additions & 3 deletions ACM.Kernel/Storage/Minio/MinioStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,13 @@ public async Task<bool> SaveFileAsync(string path, Stream stream,
}

try {
/* Todo: fix this ugly hack */
if (seekable_stream.Length == 0) {
string filename = Path.GetTempFileName();
await client.PutObjectAsync(
new PutObjectArgs().WithBucket(bucket_).WithObject(normalized_path)
.WithFileName(filename), cancellation_token);
File.Delete(filename);
return true;
} else {
await client.PutObjectAsync(
new PutObjectArgs().WithBucket(bucket_).WithObject(normalized_path)
Expand All @@ -199,12 +199,13 @@ await client.PutObjectAsync(
seekable_stream.Length -
seekable_stream.Position),
cancellation_token);
return true;
}

return true;
} catch (Exception ex) {
logger_.LogError(ex, "Error saving {Path}: {Message}", normalized_path,
ex.Message);
return false;
throw;
} finally {
if (!stream.CanSeek) {
seekable_stream.Dispose();
Expand Down
12 changes: 0 additions & 12 deletions APC.Tester/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,6 @@ await hc.GetAsync(
connection.end_point = Configuration.GetApcVar(ApcVariable.ACM_S3_ENDPOINT);
connection.bucket = Configuration.GetApcVar(ApcVariable.ACM_S3_BUCKET);


MinioStorageOptions minio_options = new() {
auto_create_bucket = true,
connection_string = connection.ToString()
};
MinioStorage st = new(minio_options, NullLogger<MinioStorage>.Instance);
HttpClient http_client = new();
HttpResponseMessage response =
await http_client.GetAsync(url, HttpCompletionOption.ResponseHeadersRead);
await using Stream remote_stream =
await response.Content.ReadAsStreamAsync();

//await st.SaveFileAsync("debug/empty-file", remote_stream);
await file.Get("list");
Console.WriteLine(Path.GetDirectoryName(path));
Expand Down

0 comments on commit 5ca8baa

Please sign in to comment.