AcademySoftwareFoundation / AcademySoftwareFoundation/rez
context sh file can be deleted too early
- Dominant language
- Python
- Stars
- 1.1k
- Forks
- 374
- Avg merge
- 9d 12h
- Merged PRs (30d)
- 5
Description
Consider the following script:
```
#!/usr/bin/env rez-python
from rez.resolved_context import ResolvedContext
c = ResolvedContext([])
p = c.execute_shell(command=['ls'])
```
When run, you will see an error like so:
```
/bin/bash: /tmp/rez_context_PdVoQP/rez-shell.sh: No such file or directory
```
This happens because rez cleans up tempfiles on exit. The subprocess created by the `execute_shell` call requires this temp sh file (because it executes it via bash). It fails because in the above script, there is no `p.wait()` to ensure that the process has completed before this happens.
The rez-shell.sh file typically looks something like this:
```
#!/bin/bash
export REZ_ENV_PROMPT="${REZ_ENV_PROMPT}>"
. "/tmp/rez_context_nrlp7yyb/context.sh"
unset BASH_ENV
if [ -z "$REZ_STORED_PROMPT" ]; then export REZ_STORED_PROMPT="$PS1"; fi
export PS1="\[\e[1m\]$REZ_ENV_PROMPT\[\e[0m\] $REZ_STORED_PROMPT"
. "/home/ajohns/rez3/lib/python3.7/site-packages/rez/completion/complete.sh"
ls
exit $?
```
What we could do is update this script, so that it deletes itself, rather than rez doing it at exit:
```
#!/bin/bash
export REZ_ENV_PROMPT="${REZ_ENV_PROMPT}>"
. "/tmp/rez_context_nrlp7yyb/context.sh"
unset BASH_ENV
if [ -z "$REZ_STORED_PROMPT" ]; then export REZ_STORED_PROMPT="$PS1"; fi
export PS1="\[\e[1m\]$REZ_ENV_PROMPT\[\e[0m\] $REZ_STORED_PROMPT"
. "/home/ajohns/rez3/lib/python3.7/site-packages/rez/completion/complete.sh"
ls
__ret__=$?
rm -f /tmp/rez_context_nrlp7yyb
exit ${__ret__}
```
This would have the following advantages:
* No tempfile cleanup code in rez
* In theory, a long-running rez proc could build up a lot of these temp dirs. That problem would go away
* Avoids bug as shown above
Contributor guide
Research direction
The entry point is ResolvedContext.execute_shell; trace how its temporary context and rez-shell.sh are created and cleaned up. Reproduce the no-p.wait() example, then verify that the command completes without a missing-file error, preserves its exit status, and cleans up its temporary files.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- bash, python
- Domain
- cli, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100