Repository: materialsproject/custodian

Issue:
[Bug]: VASP error.tar.gz files are empty
### Code snippet

```python

```

### What happened?

I am running into a strange scenario where a VASP job errors out with Custodian and an error.tar.gz file is written, but it is empty. I have attached the `custodian.json` and `error1.tar.gz` file from a recent run below.

[error.1.tar.gz](https://github.com/user-attachments/files/20075004/error.1.tar.gz)
[custodian.json](https://github.com/user-attachments/files/20075005/custodian.json)

Both my graduate student @blaked8619 and I have independently observed this for different runs. I will work on trying to put together a minimal working example to make sure I rule out anything unusual from our side.

I'm not yet convinced it isn't an "us" problem. I added a test to https://github.com/materialsproject/custodian/pull/377 and it seems to pass.

### Version

2025.4.14

### Which OS?

- [ ] MacOS
- [ ] Windows
- [ ] Linux

### Log output

```shell

```

Discussion:
codecov-commenter: ## [Codecov](https://app.codecov.io/gh/materialsproject/custodian/pull/379?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=materialsproject) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Project coverage is 69.67%. Comparing base [(`d82fe4a`)](https://app.codecov.io/gh/materialsproject/custodian/commit/d82fe4af7e28d513e671746b0057a1f3afc8192f?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=materialsproject) to head [(`5042315`)](https://app.codecov.io/gh/materialsproject/custodian/commit/50423153227d5fc45e0e5f02f3161c0aa6361694?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=materialsproject).

<details><summary>Additional details and impacted files</summary>


```diff
@@           Coverage Diff           @@
##           master     #379   +/-   ##
=======================================
  Coverage   69.67%   69.67%           
=======================================
  Files          39       39           
  Lines        3489     3489           
=======================================
  Hits         2431     2431           
  Misses       1058     1058           
```

</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/materialsproject/custodian/pull/379?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=materialsproject).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=materialsproject).

<details><summary> :rocket: New features to boost your workflow: </summary>

- :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
</details>
Andrew-S-Rosen: @shyuep: This is ready to be merged.

If it's not too much trouble to mint a new release after this, it would be a big help since this is a rather core bug fix. Thanks!

Fix (patch):
diff --git a/src/custodian/utils.py b/src/custodian/utils.py
index fe366487..b081a040 100644
--- a/src/custodian/utils.py
+++ b/src/custodian/utils.py
@@ -25,7 +25,7 @@ def backup(filenames, prefix="error", directory="./") -> None:
     logging.info(f"Backing up run to {filename}.")
     with tarfile.open(filename, "w:gz") as tar:
         for fname in filenames:
-            for file in glob(fname):
+            for file in glob(os.path.join(directory, fname)):
                 tar.add(file)
 
 


Test changes:
diff --git a/tests/test_utils.py b/tests/test_utils.py
index eafd5967..fb7df302 100644
--- a/tests/test_utils.py
+++ b/tests/test_utils.py
@@ -1,4 +1,7 @@
-from custodian.utils import tracked_lru_cache
+import tarfile
+from pathlib import Path
+
+from custodian.utils import backup, tracked_lru_cache
 
 
 def test_cache_and_clear() -> None:
@@ -25,3 +28,14 @@ def test_cache_and_clear() -> None:
 
     assert some_func(1) == 1
     assert n_calls == 3
+
+
+def test_backup(tmp_path) -> None:
+    with open(tmp_path / "INCAR", "w") as f:
+        f.write("This is a test file.")
+
+    backup(["INCAR"], directory=tmp_path)
+
+    assert Path(tmp_path / "error.1.tar.gz").exists()
+    with tarfile.open(tmp_path / "error.1.tar.gz", "r:gz") as tar:
+        assert len(tar.getmembers()) > 0