fix(core-update): --prune 시 public/storage symlink 삭제로 업로드 파일 404 되는 문제
--prune 은 릴리즈 소스에 없는 public/storage 런타임 symlink 를 orphan 으로 삭제해 업로드 파일이 404 되었다. 심층 방어 2층으로 차단한다. - 층1(예방): FilePermissionHelper 에 preserveLinkPaths 화이트리스트 추가. applyUpdate 가 public 타깃에 ['storage'] 전달 → 매칭 orphan 링크/junction 만 삭제 제외 (정밀 보호) - 층2(복구): StorageLinkHelper::ensurePublicStorageLink 신규 정적 헬퍼. CoreUpdateCommand 종료 시점(정상+핸드오프) 호출로 부재/손상 링크 멱등 재생성 (Windows junction 폴백). beta.5 migration 05 는 이 헬퍼로 위임(상위호환)
This commit is contained in:
1 parent
9251af5c6a
commit
0a6ff23132
11 files changed
+700
-66
No files matched your search
@@ -41,7 +41,7 @@ class FilePermissionHelperSymlinkTest extends TestCase
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function copyDirectory_는_symlink_를_target_추적_없이_그대로_보존합니다(): void
|
||||
public function copy_directory_는_symlink_를_target_추적_없이_그대로_보존합니다(): void
|
||||
{
|
||||
$source = $this->tempRoot.'/src';
|
||||
$dest = $this->tempRoot.'/dst';
|
||||
@@ -72,7 +72,7 @@ class FilePermissionHelperSymlinkTest extends TestCase
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function copyDirectory_는_기존_dest_디렉토리를_symlink_로_교체할_때_dest_먼저_정리합니다(): void
|
||||
public function copy_directory_는_기존_dest_디렉토리를_symlink_로_교체할_때_dest_먼저_정리합니다(): void
|
||||
{
|
||||
$source = $this->tempRoot.'/src';
|
||||
$dest = $this->tempRoot.'/dst';
|
||||
@@ -97,7 +97,7 @@ class FilePermissionHelperSymlinkTest extends TestCase
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function removeOrphanItems_는_source_부재_symlink_를_unlink_로_삭제합니다(): void
|
||||
public function remove_orphan_items_는_source_부재_symlink_를_unlink_로_삭제합니다(): void
|
||||
{
|
||||
$source = $this->tempRoot.'/src';
|
||||
$dest = $this->tempRoot.'/dst';
|
||||
@@ -119,8 +119,98 @@ class FilePermissionHelperSymlinkTest extends TestCase
|
||||
$this->assertFileExists($linkTarget.'/precious.txt', 'symlink target 의 파일은 보존되어야 한다 (재귀 삭제 사고 차단)');
|
||||
}
|
||||
|
||||
/**
|
||||
* 보호 화이트리스트(`preserveLinkPaths`)에 매칭되는 orphan symlink 는 삭제하지 않고 보존.
|
||||
*
|
||||
* 코어 업데이트 prune 모드에서 `public/storage` symlink 가 릴리즈 소스에 없다는 이유로
|
||||
* orphan 삭제되어 업로드 파일이 404 되던 결함(#43) 회귀 가드.
|
||||
*/
|
||||
#[Test]
|
||||
public function copyDirectory_는_심볼릭링크_없는_일반_디렉토리는_기존_동작을_유지합니다(): void
|
||||
public function remove_orphan_items_는_화이트리스트_symlink_를_orphan_이어도_보존합니다(): void
|
||||
{
|
||||
$source = $this->tempRoot.'/src';
|
||||
$dest = $this->tempRoot.'/dst';
|
||||
$linkTarget = $this->tempRoot.'/link_target';
|
||||
|
||||
File::ensureDirectoryExists($source);
|
||||
File::ensureDirectoryExists($dest);
|
||||
File::ensureDirectoryExists($linkTarget);
|
||||
File::put($linkTarget.'/uploaded.txt', '업로드 파일');
|
||||
|
||||
// dest 에만 존재하는 storage symlink (source 에는 없음 → orphan)
|
||||
if (! @symlink($linkTarget, $dest.'/storage')) {
|
||||
$this->markTestSkipped('symlink 생성 실패');
|
||||
}
|
||||
|
||||
// preserveLinkPaths=['storage'] 로 prune 실행 → 보호되어야 함
|
||||
FilePermissionHelper::copyDirectory($source, $dest, null, [], '', true, false, null, ['storage']);
|
||||
|
||||
$this->assertTrue(is_link($dest.'/storage'), '화이트리스트 symlink 는 orphan 이어도 보존되어야 한다');
|
||||
$this->assertSame($linkTarget, readlink($dest.'/storage'));
|
||||
$this->assertFileExists($linkTarget.'/uploaded.txt', 'symlink target 파일 보존');
|
||||
}
|
||||
|
||||
/**
|
||||
* 화이트리스트 밖 orphan symlink 는 `preserveLinkPaths=['storage']` 여도 여전히 삭제.
|
||||
*
|
||||
* 정밀 보호(무조건 보존 아님)임을 보장 — `public/storage` 만 좁게 보존한다는 설계 확정.
|
||||
*/
|
||||
#[Test]
|
||||
public function remove_orphan_items_는_화이트리스트_밖_symlink_는_여전히_삭제합니다(): void
|
||||
{
|
||||
$source = $this->tempRoot.'/src';
|
||||
$dest = $this->tempRoot.'/dst';
|
||||
$linkTarget = $this->tempRoot.'/link_target';
|
||||
|
||||
File::ensureDirectoryExists($source);
|
||||
File::ensureDirectoryExists($dest);
|
||||
File::ensureDirectoryExists($linkTarget);
|
||||
File::put($linkTarget.'/precious.txt', '중요한 파일');
|
||||
|
||||
// dest 에만 존재하는 다른 이름의 orphan symlink
|
||||
if (! @symlink($linkTarget, $dest.'/other_link')) {
|
||||
$this->markTestSkipped('symlink 생성 실패');
|
||||
}
|
||||
|
||||
// 화이트리스트는 'storage' 만 — 'other_link' 는 보호 대상 아님
|
||||
FilePermissionHelper::copyDirectory($source, $dest, null, [], '', true, false, null, ['storage']);
|
||||
|
||||
$this->assertFalse(is_link($dest.'/other_link'), '화이트리스트 밖 orphan symlink 는 삭제되어야 한다');
|
||||
$this->assertFileExists($linkTarget.'/precious.txt', 'symlink target 파일은 보존 (재귀 삭제 사고 차단)');
|
||||
}
|
||||
|
||||
/**
|
||||
* 보호 화이트리스트에 매칭되는 orphan junction 도 보존 (Windows 전용).
|
||||
*/
|
||||
#[Test]
|
||||
public function remove_orphan_items_는_화이트리스트_junction_을_orphan_이어도_보존합니다(): void
|
||||
{
|
||||
if (PHP_OS_FAMILY !== 'Windows') {
|
||||
$this->markTestSkipped('junction 은 Windows 전용 (mklink /J)');
|
||||
}
|
||||
|
||||
$source = $this->tempRoot.'/src';
|
||||
$dest = $this->tempRoot.'/dst';
|
||||
$linkTarget = $this->tempRoot.'/link_target';
|
||||
|
||||
File::ensureDirectoryExists($source);
|
||||
File::ensureDirectoryExists($dest);
|
||||
File::ensureDirectoryExists($linkTarget);
|
||||
File::put($linkTarget.'/uploaded.txt', '업로드 파일');
|
||||
|
||||
exec('cmd /c mklink /J '.escapeshellarg($dest.'/storage').' '.escapeshellarg($linkTarget).' 2>&1', $out, $code);
|
||||
if ($code !== 0 || ! is_dir($dest.'/storage')) {
|
||||
$this->markTestSkipped('junction 생성 실패: '.implode("\n", $out));
|
||||
}
|
||||
|
||||
FilePermissionHelper::copyDirectory($source, $dest, null, [], '', true, false, null, ['storage']);
|
||||
|
||||
$this->assertDirectoryExists($dest.'/storage', '화이트리스트 junction 은 orphan 이어도 보존되어야 한다');
|
||||
$this->assertFileExists($dest.'/storage/uploaded.txt', 'junction 통과 시 target 파일 접근 가능');
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function copy_directory_는_심볼릭링크_없는_일반_디렉토리는_기존_동작을_유지합니다(): void
|
||||
{
|
||||
$source = $this->tempRoot.'/src';
|
||||
$dest = $this->tempRoot.'/dst';
|
||||
@@ -145,7 +235,7 @@ class FilePermissionHelperSymlinkTest extends TestCase
|
||||
* junction 은 Windows 전용이므로 비-Windows 환경에서는 skip.
|
||||
*/
|
||||
#[Test]
|
||||
public function copyDirectory_는_windows_junction_을_파일로_오판하지_않고_보존합니다(): void
|
||||
public function copy_directory_는_windows_junction_을_파일로_오판하지_않고_보존합니다(): void
|
||||
{
|
||||
if (PHP_OS_FAMILY !== 'Windows') {
|
||||
$this->markTestSkipped('junction 은 Windows 전용 (mklink /J)');
|
||||
@@ -182,7 +272,7 @@ class FilePermissionHelperSymlinkTest extends TestCase
|
||||
* 링크 자체만 제거하는지 검증 (junction 은 isDir() 이 false 라 별도 rmdir 경로 필요).
|
||||
*/
|
||||
#[Test]
|
||||
public function removeOrphanItems_는_source_부재_junction_을_target_추적_없이_링크만_제거합니다(): void
|
||||
public function remove_orphan_items_는_source_부재_junction_을_target_추적_없이_링크만_제거합니다(): void
|
||||
{
|
||||
if (PHP_OS_FAMILY !== 'Windows') {
|
||||
$this->markTestSkipped('junction 은 Windows 전용 (mklink /J)');
|
||||
|
||||
Reference in new issue
Block a user