-
Notifications
You must be signed in to change notification settings - Fork 326
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Closes #8809
- Loading branch information
Showing
36 changed files
with
1,223 additions
and
380 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
distribution/lib/Standard/AWS/0.0.0-dev/src/Internal/Request_Body.enso
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
private | ||
from Standard.Base import all | ||
from Standard.Base.System.File import file_as_java | ||
|
||
polyglot java import software.amazon.awssdk.core.sync.RequestBody | ||
|
||
## PRIVATE | ||
from_local_file (file : File) = | ||
java_file = file_as_java file | ||
RequestBody.fromFile java_file |
66 changes: 66 additions & 0 deletions
66
distribution/lib/Standard/AWS/0.0.0-dev/src/Internal/S3_File_Write_Strategy.enso
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
private | ||
|
||
from Standard.Base import all | ||
import Standard.Base.Errors.Common.Forbidden_Operation | ||
import Standard.Base.Errors.File_Error.File_Error | ||
from Standard.Base.System.File.Generic.File_Write_Strategy import File_Write_Strategy, default_overwrite, default_append, default_raise_error, generic_remote_write_with_local_file | ||
|
||
import project.Errors.S3_Error | ||
|
||
## PRIVATE | ||
instance = | ||
File_Write_Strategy.Value default_overwrite default_append default_raise_error s3_backup create_dry_run_file remote_write_with_local_file | ||
|
||
## PRIVATE | ||
create_dry_run_file file copy_original = | ||
_ = [file, copy_original] | ||
Error.throw (Forbidden_Operation.Error "Currently dry-run is not supported for S3_File, so writing to an S3_File is forbidden if the Output context is disabled.") | ||
|
||
## PRIVATE | ||
remote_write_with_local_file file existing_file_behavior action = | ||
if existing_file_behavior == Existing_File_Behavior.Append then Error.throw (S3_Error.Error "S3 does not support appending to a file. Instead you may read it, modify and then write the new contents." Nothing) else | ||
generic_remote_write_with_local_file file existing_file_behavior action | ||
|
||
## PRIVATE | ||
A backup strategy tailored for S3. | ||
Since S3 does not support a cheap 'move' operation, the standard backup | ||
strategy that mostly relies on it does not work too well. | ||
Instead, S3 relies on a simpler strategy: | ||
1. If the destination file exists, copy it to a backup location | ||
(overwriting a previous backup file, if it was present). | ||
2. Write the new file. | ||
i. If the write succeeded, that's it. | ||
ii. If the write failed, 'restore' from the backup - copy the backup | ||
back to the original location and delete the backup file (as it's no | ||
longer needed because the original file is back with the old contents). | ||
s3_backup file action = recover_errors <| | ||
backup_location = file.parent / (file.name + ".bak") | ||
has_backup = if file.exists.not then False else | ||
Panic.rethrow <| file.copy_to backup_location replace_existing=True | ||
True | ||
|
||
revert_backup = | ||
if has_backup then | ||
Panic.rethrow <| backup_location.copy_to file | ||
Panic.rethrow <| backup_location.delete | ||
|
||
with_failure_handler revert_backup <| | ||
file.with_output_stream [File_Access.Write, File_Access.Truncate_Existing] action | ||
|
||
## PRIVATE | ||
with_failure_handler ~failure_action ~action = | ||
panic_handler caught_panic = | ||
failure_action | ||
Panic.throw caught_panic | ||
|
||
result = Panic.catch Any handler=panic_handler action | ||
if result.is_error.not then result else | ||
failure_action | ||
result | ||
|
||
|
||
## PRIVATE | ||
recover_errors ~action = | ||
Panic.catch S3_Error handler=(.convert_to_dataflow_error) <| | ||
Panic.catch File_Error handler=(.convert_to_dataflow_error) <| | ||
action |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.