diff --git a/distribution/lib/Standard/AWS/0.0.0-dev/src/Internal/S3_Path.enso b/distribution/lib/Standard/AWS/0.0.0-dev/src/Internal/S3_Path.enso index a904c3721801..87f01c393d48 100644 --- a/distribution/lib/Standard/AWS/0.0.0-dev/src/Internal/S3_Path.enso +++ b/distribution/lib/Standard/AWS/0.0.0-dev/src/Internal/S3_Path.enso @@ -156,3 +156,11 @@ type Decomposed_S3_Path if self.parts.is_empty then Nothing else new_parts = self.parts.drop (..Last 1) Decomposed_S3_Path.Value new_parts self.go_to_root + +type S3_Path_Comparator + compare x y = Ordering.compare x.bucket y.bucket . and_then Ordering.compare x.key y.key + + hash x = S3_Path_Comparator.hash_builtin x + hash_builtin x = @Builtin_Method "Default_Comparator.hash_builtin" + +Comparable.from that:S3_Path = Comparable.new that S3_Path_Comparator diff --git a/distribution/lib/Standard/AWS/0.0.0-dev/src/S3/S3_File.enso b/distribution/lib/Standard/AWS/0.0.0-dev/src/S3/S3_File.enso index 56ddae721bfc..e985570a3352 100644 --- a/distribution/lib/Standard/AWS/0.0.0-dev/src/S3/S3_File.enso +++ b/distribution/lib/Standard/AWS/0.0.0-dev/src/S3/S3_File.enso @@ -187,7 +187,7 @@ type S3_File S3_File.Value (S3_Path.Value bucket key) self.credentials files = pair.second . map key-> S3_File.Value (S3_Path.Value bucket key) self.credentials - sub_folders + files + (sub_folders + files) . sort ## ALIAS load bytes, open bytes ICON data_input @@ -616,3 +616,11 @@ translate_file_errors related_file result = s3_path = S3_Path.Value error.bucket error.key s3_file = S3_File.Value s3_path related_file.credentials Error.throw (File_Error.Not_Found s3_file) + +type S3_File_Comparator + compare x y = Ordering.compare x.s3_path y.s3_path + + hash x = S3_File_Comparator.hash_builtin x + hash_builtin x = @Builtin_Method "Default_Comparator.hash_builtin" + +Comparable.from that:S3_File = Comparable.new that S3_File_Comparator diff --git a/distribution/lib/Standard/Base/0.0.0-dev/src/Enso_Cloud/Enso_File.enso b/distribution/lib/Standard/Base/0.0.0-dev/src/Enso_Cloud/Enso_File.enso index 9fb90e46bb04..c4540ee6bb39 100644 --- a/distribution/lib/Standard/Base/0.0.0-dev/src/Enso_Cloud/Enso_File.enso +++ b/distribution/lib/Standard/Base/0.0.0-dev/src/Enso_Cloud/Enso_File.enso @@ -1,6 +1,8 @@ import project.Any.Any import project.Data.Color.Color import project.Data.Json.JS_Object +import project.Data.Ordering.Comparable +import project.Data.Ordering.Ordering import project.Data.Numbers.Integer import project.Data.Text.Encoding.Encoding import project.Data.Text.Text @@ -444,10 +446,11 @@ type Enso_File if self.is_directory.not then Error.throw (Illegal_Argument.Error "Cannot `list` a non-directory.") else # Remove secrets from the list - they are handled separately in `Enso_Secret.list`. assets = list_assets self . filter f-> f.asset_type != Enso_Asset_Type.Secret - assets.map asset-> + results = assets.map asset-> file = Enso_File.Value (self.enso_path.resolve asset.name) Asset_Cache.update file asset file + results.sort ## GROUP Output ICON folder_add @@ -583,3 +586,11 @@ File_Like.from (that : Enso_File) = File_Like.Value that ## PRIVATE Writable_File.from (that : Enso_File) = if Data_Link.is_data_link that then Data_Link_Helpers.interpret_data_link_as_writable_file that else Writable_File.Value that Enso_File_Write_Strategy.instance + +type Enso_File_Comparator + compare x y = Ordering.compare x.enso_path y.enso_path + + hash x = Enso_File_Comparator.hash_builtin x + hash_builtin x = @Builtin_Method "Default_Comparator.hash_builtin" + +Comparable.from that:Enso_File = Comparable.new that Enso_File_Comparator diff --git a/distribution/lib/Standard/Base/0.0.0-dev/src/Enso_Cloud/Internal/Enso_Path.enso b/distribution/lib/Standard/Base/0.0.0-dev/src/Enso_Cloud/Internal/Enso_Path.enso index cf521841068a..1aca5bd991be 100644 --- a/distribution/lib/Standard/Base/0.0.0-dev/src/Enso_Cloud/Internal/Enso_Path.enso +++ b/distribution/lib/Standard/Base/0.0.0-dev/src/Enso_Cloud/Internal/Enso_Path.enso @@ -1,5 +1,8 @@ private +import project.Data.Ordering.Comparable +import project.Data.Ordering.Ordering +import project.Data.Ordering.Vector_Lexicographic_Order import project.Data.Text.Text import project.Data.Vector.Vector import project.Enso_Cloud.Enso_File.Enso_File @@ -7,6 +10,7 @@ import project.Enso_Cloud.Enso_User.Enso_User import project.Error.Error import project.Errors.Illegal_Argument.Illegal_Argument import project.Errors.Unimplemented.Unimplemented +import project.Internal.Ordering_Helpers.Default_Comparator import project.Internal.Path_Helpers import project.Nothing.Nothing from project.Data.Boolean import Boolean, False, True @@ -72,3 +76,11 @@ normalize segments = ## We need to call normalize again, because technically a path `enso://a/../~/../../~` is a valid path that points to the user home and it should be correctly normalized, but requires numerous passes to do so. @Tail_Call normalize new_segments + +type Enso_Path_Comparator + compare x y = Vector_Lexicographic_Order.compare x.path_segments y.path_segments + + hash x = Enso_Path_Comparator.hash_builtin x + hash_builtin x = @Builtin_Method "Default_Comparator.hash_builtin" + +Comparable.from that:Enso_Path = Comparable.new that Enso_Path_Comparator diff --git a/test/AWS_Tests/src/S3_Spec.enso b/test/AWS_Tests/src/S3_Spec.enso index 24f88c90e3bd..026ea8b130c9 100644 --- a/test/AWS_Tests/src/S3_Spec.enso +++ b/test/AWS_Tests/src/S3_Spec.enso @@ -261,6 +261,13 @@ add_specs suite_builder = r3.should_be_a Vector r3.map .name . should_contain object_name + group_builder.specify "list should sort its output" <| + r = root.list + r.should_be_a Vector + r . should_equal (r.sort on=(x-> x.path)) + # Check sorting directly. + r . reverse . sort . should_equal r + group_builder.specify "will fail if no credentials are provided and no Default credentials are available" pending=(if AWS_Credential.is_default_credential_available then "Default AWS credentials are defined in the environment and this test has no way of overriding them, so it is impossible to test this scenario in such environment.") <| root_without_credentials = S3_File.new "s3://"+bucket_name+"/" r = root_without_credentials.list diff --git a/test/Base_Tests/src/Network/Enso_Cloud/Enso_File_Spec.enso b/test/Base_Tests/src/Network/Enso_Cloud/Enso_File_Spec.enso index 9b35a37945d4..1fc92edb98f4 100644 --- a/test/Base_Tests/src/Network/Enso_Cloud/Enso_File_Spec.enso +++ b/test/Base_Tests/src/Network/Enso_Cloud/Enso_File_Spec.enso @@ -41,6 +41,13 @@ add_specs suite_builder setup:Cloud_Tests_Setup = suite_builder.group "Enso Clou Data.list test_root.get . map .name . should_contain "test_file.json" Data.list test_root.get.path . map .name . should_contain "test_file.json" + group_builder.specify "list should sort its output" <| + r = Enso_File.home.list + r.should_be_a Vector + r . should_equal (r.sort on=.path) + # Check sorting directly. + r . reverse . sort . should_equal r + group_builder.specify "should allow to create and delete a directory" <| my_name = "my_test_dir-" + (Random.uuid.take 5) my_dir = (test_root.get / my_name).create_directory