feat: add two-digit counter suffix to vpn-configs dir (CN_YYYY-MM-DD_NN)
This commit is contained in:
@@ -271,7 +271,16 @@ def build_ovpn(
|
||||
template_content = Path(template_path).read_text()
|
||||
inline_content = Path(inline_path).read_text()
|
||||
today = date.today().strftime("%Y-%m-%d")
|
||||
out_dir = Path(output_base_dir) / f"{cn}_{today}"
|
||||
prefix = f"{cn}_{today}_"
|
||||
base = Path(output_base_dir)
|
||||
existing = [
|
||||
int(d.name[len(prefix):])
|
||||
for d in base.iterdir()
|
||||
if d.is_dir() and d.name.startswith(prefix)
|
||||
and d.name[len(prefix):].isdigit() and len(d.name[len(prefix):]) == 2
|
||||
] if base.exists() else []
|
||||
next_n = max(existing) + 1 if existing else 0
|
||||
out_dir = base / f"{prefix}{next_n:02d}"
|
||||
out_dir.mkdir(parents=True, exist_ok=True)
|
||||
out_file = out_dir / config_name
|
||||
out_file.write_text(template_content + "\n" + inline_content)
|
||||
|
||||
Reference in New Issue
Block a user