Skip to content

Check if directory is free to be used#2075

Open
AdaOrbit wants to merge 17 commits intoalire-project:masterfrom
AdaOrbit:master
Open

Check if directory is free to be used#2075
AdaOrbit wants to merge 17 commits intoalire-project:masterfrom
AdaOrbit:master

Conversation

@AdaOrbit
Copy link
Contributor

@AdaOrbit AdaOrbit commented Jan 30, 2026

This PR solves #2066 by checking if the chosen project name is free.
for --in-place it looks if alire.toml already exists. On normal project creation it checks for <project name>/alire.toml

PR creation checklist
  • A test is included, if required by the changes.
  • doc/user-changes.md has been updated, if there are user-visible changes.
  • doc/catalog-format-spec.md has been updated, if applicable.
  • BREAKING.md has been updated for major changes in alr, minor/major in catalog format.

@AdaOrbit
Copy link
Contributor Author

@AldanTanneo @mosteo ready for review!

@AldanTanneo
Copy link
Member

Ideally, there would be an error (overridable with --force) if the target directory is not empty (we don't want to overwrite existing files, or fail with a partially initialized crate.)

Is this done already elsewhere?

@AdaOrbit
Copy link
Contributor Author

AdaOrbit commented Feb 3, 2026

The current behavior is to partially initialize a crate if alire.toml already exists. Runnig alr init --no-skel foo and then alr init foo results in foo.gpr, share/ and src/foo.ads being created but then erroring out because alire.toml exists and skipping alire/ creation.

And if I understand it correctly alire.toml is what makes a directory an alire crate. What I do to mitigate this is by checking if the alire.toml file already exists. Thus stopping the user from partial creation.

I tried finding something similar that does those checks in the code base but couldn't find anything. (Maybe you know more and could guide me?)

Also a comment on the --force command for init: I don't think that it is a good idea. It should rather be the developers responsibility on ensure all the files that alire is going to "overwrite" are already gone and usable. Or else we end up with users who ask "I used --force and main.gpr, src/main.ads and more got overwriten. How to fix?"

@AldanTanneo
Copy link
Member

Also a comment on the --force command for init: I don't think that it is a good idea. It should rather be the developers responsibility on ensure all the files that alire is going to "overwrite" are already gone and usable. Or else we end up with users who ask "I used --force and main.gpr, src/main.ads and more got overwriten. How to fix?"

What I meant is not using --force to overwrite files, but to say "try anyway" when the directory is not empty. It would still fail if it tries to overwrite existing user files.

Detecting when the directory is not empty would avoid the partial crate initialization altogether, and then using --force would potentially end up with a partially initialized crate (with skeleton files) but the error would not be alr's fault. Does that make sense?

@AldanTanneo
Copy link
Member

Of course, this can be on top of alire.toml detection, as the crate creation would fail unconditionally if there is already an alire.toml file present.

@AdaOrbit
Copy link
Contributor Author

AdaOrbit commented Feb 6, 2026

I should look more into the control flow to understand the current design better. I'll take a look at it again and see where it's best to check and add features.

@mosteo mosteo changed the title Check if director is free to be used Check if directory is free to be used Feb 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants