alire-project / alire

Command-line tool from the Alire project and supporting library
GNU General Public License v3.0
287 stars 49 forks source link

Program error in alire-publish.adb:1129 finalize/adjust raised exception #1077

Open stcarrez opened 2 years ago

stcarrez commented 2 years ago

I'm using Alire 1.2 official version.

When trying to publish some projects, I'm getting a PROGRAM_ERROR exception at the end of publish when it succeeds.


Publishing assistant: step 6 of 6: Generate index manifest
✓ Your index manifest file has been generated at /src/awa/ada-awa/ada-servlet/alire/releases/servletada_aws-1.5.3.toml
ⓘ Please upload this file to https://github.com/stcarrez/alire-index/upload/stable-1.2/index/se/servletada_aws to create a pull request against the community index.
stderr: ADA.IO_EXCEPTIONS.USE_ERROR
stderr: directory tree rooted at "/src/awa/ada-awa/ada-servlet/alire/tmp/alr-bsib.tmp/alire/cache/dependencies/aws_21.0.0_57fddf8f/install_dir/lib" could not be deleted
stderr: raised ADA.IO_EXCEPTIONS.USE_ERROR : directory tree rooted at "/src/awa/ada-awa/ada-servlet/alire/tmp/alr-bsib.tmp/alire/cache/dependencies/aws_21.0.0_57fddf8f/install_dir/lib" could not be deleted
[/opt/applications/gnat-2021/bin/alr]
0xeeefde ada__directories__delete_tree at ???
0xeeece4 ada__directories__delete_tree at ???
0xeeece4 ada__directories__delete_tree at ???
0xeeece4 ada__directories__delete_tree at ???
0xeeece4 ada__directories__delete_tree at ???
0xeeece4 ada__directories__delete_tree at ???
0xeeece4 ada__directories__delete_tree at ???
0x788b85 Alire.Directories.Delete_Tree at alire-directories.adb:177
0x78ead0 Alire.Directories.Finalize at alire-directories.adb:529
0x785695 Alire.Directories.Temp_FileDF at alire-directories.ads:221
0xb098e3 Alire.Publish.DataDF at alire-publish.adb:120
0xb1ce43 Alire.Publish.Remote_Origin.B_15 at alire-publish.adb:1173
0xb1c970 Alire.Publish.Remote_Origin at alire-publish.adb:1165
0xb1a39d Alire.Publish.Local_Repository at alire-publish.adb:1090
0x4b4a43 Alr.Commands.Publish.Execute at alr-commands-publish.adb:56
0x52aa0e Alr.Commands.Sub_Cmd.Execute at clic-subcommand-instance.adb:742
0x5363ff Alr.Commands.Execute at alr-commands.adb:492
0x42b9aa Alr.Main at alr-main.adb:10
0x42e277 Main at b__alr-main.adb:2132
[/lib/x86_64-linux-gnu/libc.so.6]
0x7fd1a71f1081
[/opt/applications/gnat-2021/bin/alr]
0x42b88c _start at ???
0xfffffffffffffffe

stderr: PROGRAM_ERROR
stderr: alire-publish.adb:1129 finalize/adjust raised exception
stderr: raised PROGRAM_ERROR : alire-publish.adb:1129 finalize/adjust raised exception
[/opt/applications/gnat-2021/bin/alr]
0xb1cecc Alire.Publish.Remote_Origin.B_15 at alire-publish.adb:1173
0xb1c970 Alire.Publish.Remote_Origin at alire-publish.adb:1165
0xb1a39d Alire.Publish.Local_Repository at alire-publish.adb:1090
0x4b4a43 Alr.Commands.Publish.Execute at alr-commands-publish.adb:56
0x52aa0e Alr.Commands.Sub_Cmd.Execute at clic-subcommand-instance.adb:742
0x5363ff Alr.Commands.Execute at alr-commands.adb:492
0x42b9aa Alr.Main at alr-main.adb:10
0x42e277 Main at b__alr-main.adb:2132
[/lib/x86_64-linux-gnu/libc.so.6]
0x7fd1a71f1081
[/opt/applications/gnat-2021/bin/alr]
0x42b88c _start at ???
0xfffffffffffffffe

error: alire-publish.adb:1129 finalize/adjust raised exception
error: alr encountered an unexpected error, re-run with -d for details.

It seems to occur on projects where I'm using aws as dependency. The generated Alire toml file is correct and the crash occurs probably in the cleanup phase of the build process.

stcarrez commented 2 years ago

LOL! I've found the reason and it is caused by a bug in Ada.Directories (filed in 2014):

When you build AWS, you get a symbolic link to a non-existing file:

$ ls -l /src/awa/ada-awa/ada-servlet/alire/tmp/alr-bsib.tmp/alire/cache/dependencies/aws_21.0.0_57fddf8f/install_dir/lib/
lrwxrwxrwx 1 ciceron ciceron 32 juil.  3 13:56 libaws.so -> ../lib/aws.relocatable/libaws.so

In fact you cannot use Ada.Directories.Delete_Tree to reliably delete a build directory. I've discovered that recently with Porion. This is why I've implemented a safer delete operation in my library Ada Utility Library, see Util.Files.Delete_Tree

The root issue in Ada.Directories package is that it uses stat instead of lstat to have information about a file. Then, it checks for the existence of the file before allowing its deletion. Since stat fails to resolve the target link, the target file is not found but the symbolic link is real and the deletion is not done. At the end, the directory is not empty.

I doubt that Ada.Directories will ever be fixed since the issue was reported in 2014 and nothing changed.

It is also not clear whether the Ada.Directories.Kind and Ada.Directories.Exists should be based on stat or lstat. This makes a big difference on Unix depending on what you want to do :-). Now, in most cases people use stat because you are interested by the target file (except when you delete it!!!).

Fabien-Chouteau commented 2 years ago

Deleting files is hard :cry: We also have an issue with deleting the index on Windows.

Maybe we should use you implementation.