Skip to content

armgit / peach

Public Imported from GitHub
0

Peach: Local-first video metadata scraper and media manager.

feat(desktop): 安装包支持选择程序目录

longmeidao523ea204cb85
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index 5b12965b3..3907542b6 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -65,6 +65,9 @@ jobs:
choco install innosetup --version 6.7.3 --yes --no-progress
if ($LASTEXITCODE -ne 0) { throw 'Inno Setup 安装失败' }
}
+ - name: 验证安装目录选择与保护
+ shell: pwsh
+ run: '& ./scripts/test.ps1 -Scope packaging -Focus test_desktop_installer'
- name: 构建独立目录包与安装包
shell: pwsh
run: '& ./scripts/build_windows.ps1 -Installer -CloudflaredPath "$env:RUNNER_TEMP/cloudflared.exe"'
@@ -102,10 +105,10 @@ jobs:
- name: 静默安装、验收并卸载安装包
shell: pwsh
run: |
+ $Installed = Join-Path $env:RUNNER_TEMP 'Peach 安装验收\自定义目录'
$Setup = Start-Process -FilePath './Peach-${{ needs.windows.outputs.version }}-windows-x64-setup.exe' `
- -ArgumentList '/VERYSILENT', '/SUPPRESSMSGBOXES', '/NORESTART' -Wait -PassThru
+ -ArgumentList '/VERYSILENT', '/SUPPRESSMSGBOXES', '/NORESTART', "/DIR=`"$Installed`"" -Wait -PassThru
if ($Setup.ExitCode -ne 0) { throw "安装包退出码 $($Setup.ExitCode)" }
- $Installed = Join-Path $env:LOCALAPPDATA 'Programs\Peach'
$Key = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall\{02D9748A-78F6-4866-AC75-918177194DAB}_is1'
$Menu = Join-Path $env:APPDATA 'Microsoft\Windows\Start Menu\Programs\Peach.lnk'
if (-not (Test-Path -LiteralPath $Key) -or -not (Test-Path -LiteralPath $Menu)) { throw '安装包没有登记卸载项或开始菜单项' }
diff --git a/README.md b/README.md
index 2e7a1edcb..544311a48 100644
--- a/README.md
+++ b/README.md
@@ -99,7 +99,7 @@ https://github.com/user-attachments/assets/a5610874-e611-41bb-be22-7d99f0d64b62
### Windows
1. 从 [Releases](https://github.com/peach-mitao/peach/releases) 下载其中一种:
- - 安装包 `Peach-<版本>-windows-x64-setup.exe`:双击安装,不需要管理员权限,开始菜单里有 Peach,可以在系统设置里卸载。
+ - 安装包 `Peach-<版本>-windows-x64-setup.exe`:双击安装,可选择安装目录,不需要管理员权限,开始菜单里有 Peach,可以在系统设置里卸载。
- 免安装包 `Peach-<版本>-windows-x64.zip`:右键「全部解压」,双击里面的 `Peach.exe`。
2. 浏览器会打开首次设置页。
3. 选好媒体文件夹和谁能访问,开始扫描。
diff --git a/docs/REUSE.md b/docs/REUSE.md
index d16c1daed..e85739308 100644
--- a/docs/REUSE.md
+++ b/docs/REUSE.md
@@ -256,7 +256,7 @@ JAV 默认封面(官方封面/预览图)与视频默认大小(大图/
- GET 重试归现有连接器:[HTTPX 原生重试](https://www.python-httpx.org/advanced/transports/)只覆盖连接失败,统一不了 HTTPX 与 curl_cffi 的读超时、临时 HTTP 状态与页面进度。POST 不重放,403 单次终止。
- 标签发布用系统 Git、GitHub CLI(MIT)与 [Actions runs REST API](https://docs.github.com/en/rest/actions/workflow-runs);[release_tag.py](../scripts/release_tag.py) 管版本、主线归属、同提交成功 CI 与不可覆盖策略,工作流用 Release 制品验收。
- 独立 Windows 测试包用 PyInstaller(GPL-2.0-or-later,带 bootloader 分发例外)的 [onedir 与自启动子进程](https://pyinstaller.org/en/stable/common-issues-and-pitfalls.html):完整目录共享资源、避免重复解包,onefile 托盘入口只用于源码部署;Peach 保留进程所有权、数据目录、配置和扫描策略。
-- Windows 安装包用 Inno Setup 6.7.3(Inno Setup License,允许免费分发)与官方 `Files/Languages/Unofficial/ChineseSimplified.isl` 译文(在 `scripts/installer/`)。`.iss` 只管文件、开始菜单项和卸载登记;停托盘、补迁移、撤快捷方式经 `desktop_installer` 调已有入口,自更新与应用内卸载是唯一实现。
+- Windows 安装包用 Inno Setup 6.7.3(Inno Setup License,允许免费分发)与官方 `Files/Languages/Unofficial/ChineseSimplified.isl` 译文(在 `scripts/installer/`)。目录选择与升级目录记忆复用官方 [`DisableDirPage`](https://jrsoftware.org/ishelp/topic_setup_disabledirpage.htm)、[`UsePreviousAppDir`](https://jrsoftware.org/ishelp/topic_setup_usepreviousappdir.htm);Peach 在目录页和安装前校验独立目录、数据重叠、目录链接、写入权限及已有安装位置,使用现有 Inno Setup,无新增依赖。`test_desktop_installer.py` 编译正式脚本并运行共用判据的隔离 EXE,覆盖中文和空格路径、原位升级及目录保护,不安装到真实位置、不写 ledger。`.iss` 只管文件、开始菜单项和卸载登记;停托盘、补迁移、撤快捷方式经 `desktop_installer` 调已有入口,自更新与应用内卸载是唯一实现。
- 运行一致性:用 `LedgerDatabase.write_transaction` 的提交边界与 `OrderedDict`;HTTP 导航用 FastAPI/Starlette,图片复验用 `StaticFiles.is_not_modified` 与 `FileResponse` 的 ETag;列表用 SQLite 的 IN/UNION 保留隐藏标签与多标签组合,不引查询框架。
- 馆藏侧栏用 `catalog_filter` 的列表条件,已保存在线卡片用关注来源的标签与封面投影,详情用 `openFollowDetail`、Video.js 与媒体队列;导航范围与标签计数在 `frontend/src/sidebar.ts`。
- wheel 资源用 setuptools 的 `build_py.copy_tree`([官方包内数据建议](https://setuptools.pypa.io/en/stable/userguide/datafiles.html)),钩子只复制三个既有资源目录,因为源码、桌面构建和前端产物共用其维护位置。
diff --git a/docs/TESTING_DESKTOP.md b/docs/TESTING_DESKTOP.md
index f50e70180..27be71180 100644
--- a/docs/TESTING_DESKTOP.md
+++ b/docs/TESTING_DESKTOP.md
@@ -5,16 +5,18 @@ Windows 测试版有安装包和免安装包两种,程序文件相同,都不
| | 安装包 | 免安装包 |
| --- | --- | --- |
| 文件 | `Peach-<版本>-windows-x64-setup.exe` | `Peach-<版本>-windows-x64.zip` |
-| 程序位置 | 固定在 `%LOCALAPPDATA%\Programs\Peach`,不需要管理员权限 | 解压到哪里就在哪里 |
+| 程序位置 | 可选择,默认 `%LOCALAPPDATA%\Programs\Peach`,不需要管理员权限 | 解压到哪里就在哪里 |
| 开始菜单与系统设置里的卸载项 | 有 | 没有 |
两种的数据都在 `%LOCALAPPDATA%\Peach\peach-data`,换用另一种时设置和数据库照常沿用。
+安装目录须为当前用户可写的独立文件夹,上级目录也须可写,以便自动更新。可选择空文件夹或已有的 Peach 安装目录;程序目录不能与数据目录重叠,也不能经过目录链接。升级默认沿用已有安装目录。需要换位置时,先卸载并保留数据,再安装到新目录。
+
## 开始使用
1. 从 [GitHub Releases](https://github.com/peach-mitao/peach/releases) 下载其中一种,以及 `SHA256SUMS.txt`。
2. 核对哈希:在 PowerShell 里运行 `Get-FileHash .\<下载的文件名>`,结果应与 `SHA256SUMS.txt` 里对应的那一行相同(不区分大小写)。
-3. 安装包:双击,按提示完成安装,最后一步勾选「运行 Peach」。免安装包:右键压缩包,选「全部解压」,保留整个 `Peach` 文件夹,不要只拿出 `Peach.exe`,然后双击 `Peach.exe`。
+3. 安装包:双击,选择安装目录,按提示完成安装,最后一步勾选「运行 Peach」。免安装包:右键压缩包,选「全部解压」,保留整个 `Peach` 文件夹,不要只拿出 `Peach.exe`,然后双击 `Peach.exe`。
4. 浏览器会打开首次设置页。
5. 添加媒体文件夹(可以用「选择文件夹」挑选),选择谁可以访问、要不要设访问密码、是否立即扫描,然后提交。
6. 设置完成后自动进入馆藏,右下角会显示一份安装教程,照着做或逐项跳过都可以。
diff --git a/scripts/installer/directory-contract-test.iss b/scripts/installer/directory-contract-test.iss
new file mode 100644
index 000000000..fdb22e686
--- /dev/null
+++ b/scripts/installer/directory-contract-test.iss
@@ -0,0 +1,24 @@
+; InitializeSetup 只运行真实目录判据并写测试结果,不创建安装目录、登记项或快捷方式。
+[Setup]
+AppName=Peach directory contract
+AppVersion=1.0
+AppId=PeachDirectoryContract
+PrivilegesRequired=lowest
+CreateAppDir=no
+Uninstallable=no
+OutputBaseFilename=directory-contract
+
+[Code]
+#include "directory-validation.iss"
+
+function InitializeSetup(): Boolean;
+var
+ Error: String;
+begin
+ Error := DirectoryError(ExpandConstant('{param:program}'),
+ ExpandConstant('{param:data}'), ExpandConstant('{param:previous}'));
+ if Error = '' then
+ Error := 'ok';
+ SaveStringToFile(ExpandConstant('{param:result}'), Error, False);
+ Result := False;
+end;
diff --git a/scripts/installer/directory-validation.iss b/scripts/installer/directory-validation.iss
new file mode 100644
index 000000000..f3f6acab6
--- /dev/null
+++ b/scripts/installer/directory-validation.iss
@@ -0,0 +1,118 @@
+{ 安装器与隔离回归共用的目录判据。返回 CustomMessages 的键,空串表示可安装。 }
+function DirectoryAttributes(Name: String): Cardinal;
+ external '[email protected] stdcall';
+
+function DirectoryPath(Name: String): String;
+var
+ Parent: String;
+begin
+ Name := RemoveBackslashUnlessRoot(ExpandFileName(Name));
+ Parent := ExtractFileDir(Name);
+ if DirExists(Name) or (Parent = Name) or (Parent = '') then
+ Result := AddBackslash(LowerCase(GetShortName(Name)))
+ else
+ Result := DirectoryPath(Parent) + AddBackslash(LowerCase(ExtractFileName(Name)));
+end;
+
+function HasDirectoryLink(Name: String): Boolean;
+var
+ Parent: String;
+ Attributes: Cardinal;
+begin
+ Result := False;
+ Name := RemoveBackslashUnlessRoot(ExpandFileName(Name));
+ while Name <> '' do
+ begin
+ Attributes := DirectoryAttributes(Name);
+ if (Attributes <> $FFFFFFFF) and ((Attributes and $400) <> 0) then
+ begin
+ Result := True;
+ Exit;
+ end;
+ Parent := ExtractFileDir(Name);
+ if Parent = Name then
+ Exit;
+ Name := Parent;
+ end;
+end;
+
+function CanWriteDirectory(Name: String): Boolean;
+var
+ Probe: String;
+begin
+ Result := False;
+ try
+ Probe := GenerateUniqueName(Name, '.tmp');
+ if SaveStringToFile(Probe, '', False) then
+ Result := DeleteFile(Probe);
+ except
+ Result := False;
+ end;
+end;
+
+function DirectoryError(ProgramDirectory, DataDirectory, PreviousDirectory: String): String;
+var
+ ProgramPath, DataPath, Parent: String;
+ Found: TFindRec;
+ Installed: Boolean;
+begin
+ Result := '';
+ ProgramPath := DirectoryPath(ProgramDirectory);
+ DataPath := DirectoryPath(DataDirectory);
+ if (Pos(ProgramPath, DataPath) = 1) or (Pos(DataPath, ProgramPath) = 1) then
+ Result := 'DirectoryOverlapsData'
+ else if HasDirectoryLink(ProgramDirectory) or HasDirectoryLink(DataDirectory) then
+ Result := 'DirectoryLink';
+ if Result <> '' then
+ Exit;
+ if FileExists(ProgramDirectory) or
+ (RemoveBackslashUnlessRoot(ExpandFileName(ProgramDirectory)) =
+ AddBackslash(ExtractFileDrive(ExpandFileName(ProgramDirectory)))) then
+ begin
+ Result := 'DirectoryNotDedicated';
+ Exit;
+ end;
+
+ Installed := FileExists(AddBackslash(ProgramDirectory) + 'Peach.exe') and
+ FileExists(AddBackslash(ProgramDirectory) + 'unins000.exe');
+ if not Installed and FindFirst(AddBackslash(ProgramDirectory) + '*', Found) then
+ begin
+ try
+ repeat
+ if (Found.Name <> '.') and (Found.Name <> '..') then
+ begin
+ Result := 'DirectoryNotDedicated';
+ Exit;
+ end;
+ until not FindNext(Found);
+ finally
+ FindClose(Found);
+ end;
+ end;
+ if (PreviousDirectory <> '') and
+ (DirectoryPath(PreviousDirectory) <> ProgramPath) and
+ FileExists(AddBackslash(PreviousDirectory) + 'unins000.exe') then
+ begin
+ Result := 'DirectoryMove';
+ Exit;
+ end;
+
+ { 更新事务在程序目录的上级创建,现有程序目录本身也必须可写。 }
+ if DirExists(ProgramDirectory) and not CanWriteDirectory(ProgramDirectory) then
+ begin
+ Result := 'DirectoryNotWritable';
+ Exit;
+ end;
+ Parent := ExtractFileDir(RemoveBackslashUnlessRoot(ExpandFileName(ProgramDirectory)));
+ while (Parent <> '') and not DirExists(Parent) do
+ begin
+ if ExtractFileDir(Parent) = Parent then
+ begin
+ Result := 'DirectoryNotWritable';
+ Exit;
+ end;
+ Parent := ExtractFileDir(Parent);
+ end;
+ if (Parent = '') or not CanWriteDirectory(Parent) then
+ Result := 'DirectoryNotWritable';
+end;
diff --git a/scripts/installer/peach.iss b/scripts/installer/peach.iss
index 0246b8ee5..7d3f27d49 100644
--- a/scripts/installer/peach.iss
+++ b/scripts/installer/peach.iss
@@ -1,6 +1,6 @@
; Peach Windows 安装包。由 scripts/build_windows.ps1 -Installer 调用 ISCC 编译:
; ISCC /DAppVersion=<版本> /DSourceDir=<独立目录包 Peach\> /DOutputDir=<输出目录> peach.iss
-; 装的内容与免安装包逐字节相同,差别只在程序目录固定、开始菜单项和「应用和功能」里的登记。
+; 装的内容与免安装包逐字节相同,安装器提供目录选择、开始菜单项和「应用和功能」里的登记。
; 自更新、开机自启、桌面图标和应用内卸载仍由 Peach 管,约定见 src/peach/desktop_installer.py。
#ifndef AppVersion
@@ -25,9 +25,8 @@ AppSupportURL=https://github.com/peach-mitao/peach/issues
; 只装到当前用户:自更新在程序目录旁边建事务目录再整目录切换,Program Files 不可写。
PrivilegesRequired=lowest
DefaultDirName={userpf}\Peach
-; 程序目录固定。数据在 %LOCALAPPDATA%\Peach\peach-data,选到它的上层会让程序与数据重叠,
-; 自更新和应用内卸载都会因此拒绝工作。
-DisableDirPage=yes
+DisableDirPage=no
+UsePreviousAppDir=yes
DisableProgramGroupPage=yes
ArchitecturesAllowed=x64compatible
ArchitecturesInstallIn64BitMode=x64compatible
@@ -49,6 +48,11 @@ Name: "chs"; MessagesFile: "ChineseSimplified.isl"
chs.StillRunning=Peach 仍在运行,未能自动退出。请从托盘菜单退出 Peach 后重试。
chs.MigrationFailed=本地数据库未能更新到新版本,Peach 启动后可能出错。升级前的备份在数据目录的 database 文件夹里,文件名以 ledger.pre-migrate- 开头。
chs.DataKept=Peach 已卸载。设置、本地数据库和观看记录保留在 %1,需要时可手动删除;媒体文件不受影响。
+chs.DirectoryOverlapsData=程序目录不能与 Peach 数据目录重叠。请选择独立的程序文件夹。
+chs.DirectoryNotDedicated=请选择空文件夹或已有的 Peach 安装目录。卸载 Peach 时会移除整个程序文件夹。
+chs.DirectoryNotWritable=当前用户无法写入程序目录或其上级目录。请选择有写入权限的位置,以便安装和更新 Peach。
+chs.DirectoryLink=程序目录和数据目录不能经过目录链接。请选择普通文件夹。
+chs.DirectoryMove=请先卸载现有 Peach(保留数据),再选择新的安装目录。
[Tasks]
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked
@@ -79,11 +83,44 @@ begin
Result := ExpandConstant('{localappdata}\Peach\peach-data');
end;
+#include "directory-validation.iss"
+
+function InstallationDirectoryError(): String;
+var
+ PreviousDirectory: String;
+begin
+ PreviousDirectory := '';
+ RegQueryStringValue(HKCU,
+ 'Software\Microsoft\Windows\CurrentVersion\Uninstall\{02D9748A-78F6-4866-AC75-918177194DAB}_is1',
+ 'Inno Setup: App Path', PreviousDirectory);
+ Result := DirectoryError(WizardDirValue(), DataRoot(), PreviousDirectory);
+ if Result = '' then
+ Result := DirectoryError(WizardDirValue(), ExpandConstant('{localappdata}\Peach\peach-data'), PreviousDirectory);
+ if Result <> '' then
+ Result := CustomMessage(Result);
+end;
+
+function NextButtonClick(CurPageID: Integer): Boolean;
+var
+ Error: String;
+begin
+ Result := True;
+ if CurPageID = wpSelectDir then
+ begin
+ Error := InstallationDirectoryError();
+ Result := Error = '';
+ if not Result then
+ SuppressibleMsgBox(Error, mbError, MB_OK, IDOK);
+ end;
+end;
+
function PrepareToInstall(var NeedsRestart: Boolean): String;
var
ResultCode: Integer;
begin
- Result := '';
+ Result := InstallationDirectoryError();
+ if Result <> '' then
+ Exit;
{ 退出码 1 是托盘没能退出;2 是不认这个参数的旧版本,交给 CloseApplications 处理。 }
if FileExists(ExpandConstant('{app}\Peach.exe')) then
if Exec(ExpandConstant('{app}\Peach.exe'), '--installer-stop', ExpandConstant('{app}'),
diff --git a/tests/test_desktop_installer.py b/tests/test_desktop_installer.py
index 54d63cbef..e6e729e8b 100644
--- a/tests/test_desktop_installer.py
+++ b/tests/test_desktop_installer.py
@@ -1,6 +1,11 @@
"""安装包与 Peach 自身更新、卸载机制之间的约定。"""
from pathlib import Path
+import ctypes
+import os
import re
+import shutil
+import subprocess
+import sys
import tempfile
import unittest
from unittest.mock import patch
@@ -26,6 +31,130 @@ class InstallerContractTests(unittest.TestCase):
name = iss_value(r'^Name: "\{userprograms\}\\([^"]+)"; Filename: "\{app\}\\Peach\.exe"')
self.assertEqual(name + ".lnk", desktop_installer.MENU_SHORTCUT)
+ def test_directory_page_and_upgrade_directory_are_enabled(self):
+ self.assertEqual(iss_value(r"^DisableDirPage=(.+)$"), "no")
+ self.assertEqual(iss_value(r"^UsePreviousAppDir=(.+)$"), "yes")
+
+
[email protected](sys.platform == "win32", "安装器目录回归需要 Windows")
+class InstallerDirectoryTests(unittest.TestCase):
+ @classmethod
+ def setUpClass(cls):
+ candidates = [os.environ.get("PEACH_ISCC"), shutil.which("ISCC.exe")]
+ for base in (os.environ.get("ProgramFiles(x86)"),
+ str(Path(os.environ.get("LOCALAPPDATA", "")) / "Programs")):
+ if base:
+ candidates.append(str(Path(base) / "Inno Setup 6/ISCC.exe"))
+ cls.compiler = next((p for p in candidates if p and Path(p).is_file()), None)
+ if not cls.compiler:
+ raise unittest.SkipTest("未取得 Inno Setup 编译器")
+ temporary = tempfile.TemporaryDirectory()
+ cls.addClassCleanup(temporary.cleanup)
+ cls.build = Path(temporary.name).resolve()
+ fixture = ISS.parent / "directory-contract-test.iss"
+ cls.compile(fixture, f"/O{cls.build}")
+
+ @classmethod
+ def compile(cls, script, *options):
+ compiled = subprocess.run([cls.compiler, "/Q", *options, str(script)],
+ capture_output=True, timeout=120)
+ if compiled.returncode:
+ raise AssertionError(compiled.stdout.decode(errors="replace") +
+ compiled.stderr.decode(errors="replace"))
+
+ def setUp(self):
+ temporary = tempfile.TemporaryDirectory()
+ self.addCleanup(temporary.cleanup)
+ self.root = Path(temporary.name).resolve()
+ self.data = self.root / "data"
+ self.data.mkdir()
+
+ def check_directory(self, program, expected, *, previous="", data=None):
+ result = self.root / "result.txt"
+ result.unlink(missing_ok=True)
+ subprocess.run([str(self.build / "directory-contract.exe"), "/VERYSILENT",
+ "/SUPPRESSMSGBOXES", "/NORESTART", f"/program={program}",
+ f"/data={data or self.data}", f"/previous={previous}",
+ f"/result={result}"], capture_output=True, timeout=30)
+ self.assertEqual(result.read_text(), expected)
+
+ def test_custom_directory_with_spaces_and_unicode(self):
+ program = self.root / "自选 目录/Peach"
+ self.check_directory(program, "ok")
+ self.assertFalse(program.exists())
+
+ def test_empty_existing_directory(self):
+ program = self.root / "Peach"
+ program.mkdir()
+ self.check_directory(program, "ok")
+ self.assertEqual(list(program.iterdir()), [])
+
+ def test_data_directory_and_ancestors_and_children_are_rejected(self):
+ for program in (self.data, self.root, self.data / "Peach",
+ self.data / "child/../Peach", str(self.data).upper()):
+ with self.subTest(program=program):
+ self.check_directory(program, "DirectoryOverlapsData")
+
+ def test_sibling_with_the_same_prefix_is_independent(self):
+ self.check_directory(self.root / "data-program", "ok")
+
+ def test_short_path_alias_of_data_is_rejected(self):
+ data = self.root / "Peach data directory"
+ data.mkdir()
+ buffer = ctypes.create_unicode_buffer(32768)
+ size = ctypes.windll.kernel32.GetShortPathNameW(str(data), buffer, len(buffer))
+ self.assertGreater(size, 0)
+ self.check_directory(Path(buffer.value) / "Peach", "DirectoryOverlapsData", data=data)
+
+ def test_directory_and_update_parent_must_be_writable(self):
+ parent = self.root / "programs"
+ program = parent / "Peach"
+ program.mkdir(parents=True)
+ for denied in (program, parent):
+ with self.subTest(denied=denied):
+ changed = subprocess.run(["icacls", str(denied), "/deny", "*S-1-1-0:(W)"],
+ capture_output=True, timeout=10)
+ try:
+ self.assertEqual(changed.returncode, 0, changed.stderr)
+ self.check_directory(program, "DirectoryNotWritable")
+ finally:
+ restored = subprocess.run(["icacls", str(denied), "/remove:d", "*S-1-1-0"],
+ capture_output=True, timeout=10)
+ self.assertEqual(restored.returncode, 0, restored.stderr)
+
+ def test_unrelated_nonempty_directory_is_rejected(self):
+ program = self.root / "media"
+ program.mkdir()
+ original = program / "personal.txt"
+ original.write_text("keep")
+ self.check_directory(program, "DirectoryNotDedicated")
+ self.assertEqual(original.read_text(), "keep")
+
+ def test_existing_installation_can_be_upgraded_in_place(self):
+ program = self.root / "Peach"
+ program.mkdir()
+ for name in ("Peach.exe", "unins000.exe"):
+ (program / name).touch()
+ self.check_directory(program, "ok", previous=program)
+ self.check_directory(self.root / "elsewhere", "DirectoryMove", previous=program)
+
+ def test_directory_junction_is_rejected(self):
+ alias = self.root / "alias"
+ made = subprocess.run(["cmd", "/c", "mklink", "/J", str(alias), str(self.data)],
+ capture_output=True, timeout=10)
+ self.assertEqual(made.returncode, 0, made.stderr)
+ self.addCleanup(alias.rmdir)
+ self.check_directory(alias / "Peach", "DirectoryLink")
+ self.check_directory(self.root / "Peach", "DirectoryLink", data=alias)
+
+ def test_production_installer_compiles_with_directory_validation(self):
+ payload = self.root / "payload"
+ payload.mkdir()
+ (payload / "Peach.exe").write_bytes(b"compile fixture")
+ self.compile(ISS, "/DAppVersion=0.0.0", f"/DSourceDir={payload}",
+ f"/DOutputDir={self.root}")
+ self.assertTrue((self.root / "Peach-0.0.0-windows-x64-setup.exe").is_file())
+
class InstallerHandoffTests(unittest.TestCase):
def setUp(self):