Skip to content

Commit

Permalink
fix: create backup file with random filename
Browse files Browse the repository at this point in the history
Signed-off-by: Frost Ming <me@frostming.com>
  • Loading branch information
frostming committed Oct 5, 2024
1 parent 7e0a8e6 commit 10f051f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions news/3193.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Create backup file with random filename to avoid conflicts.
4 changes: 3 additions & 1 deletion src/pdm/formats/uv.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import tempfile
from collections.abc import Iterator
from contextlib import ExitStack, contextmanager
from dataclasses import dataclass, field
Expand Down Expand Up @@ -64,7 +65,8 @@ def build_pyproject_toml(self) -> Path:

def _enter_path(self, path: Path) -> Path:
if path.exists():
backup = path.rename(path.with_name(f"{path.name}.bak"))
name = tempfile.mktemp(dir=path.parent, prefix=path.name)
backup = path.rename(name)

@self.stack.callback
def restore() -> None:
Expand Down

0 comments on commit 10f051f

Please sign in to comment.