diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4cf1bc8..21ac9eb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -263,6 +263,19 @@ jobs: { echo "ERROR: hello.txt not recorded as 0644"; exit 1; } "$BFC" list -l test.bfc | grep -q -- '^drwxr-xr-x .*test_data/subdir' || { echo "ERROR: subdir not recorded as 0755"; exit 1; } + + # A Windows-style path ("test_data\", as typed in PowerShell) must be + # stored with '/' separators, and extract back into test_data/ + "$BFC" create backslash.bfc 'test_data\' + "$BFC" list backslash.bfc + if "$BFC" list backslash.bfc | grep -qF '\'; then + echo "ERROR: container paths contain a backslash"; exit 1 + fi + mkdir extract_backslash + "$BFC" extract -C extract_backslash backslash.bfc + [ -f extract_backslash/test_data/subdir/nested.txt ] || + { echo "ERROR: test_data/subdir/nested.txt not extracted"; exit 1; } + rm -rf extract_backslash backslash.bfc "$BFC" info test.bfc "$BFC" verify test.bfc "$BFC" verify --deep test.bfc diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 938dffc..4084b73 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -4,6 +4,11 @@ on: push: tags: - "v*" + # Build and check the packages, without publishing, when this workflow + # changes, so packaging problems show up before a release is tagged + pull_request: + paths: + - ".github/workflows/release.yml" jobs: build-release: @@ -226,7 +231,14 @@ jobs: - name: Get version id: get_version shell: bash - run: echo "version=${GITHUB_REF#refs/tags/}" >> "$GITHUB_OUTPUT" + run: | + if [[ "$GITHUB_REF" == refs/tags/* ]]; then + echo "version=${GITHUB_REF#refs/tags/}" >> "$GITHUB_OUTPUT" + else + # Not a release: name the packages after the project version + v=$(sed -n 's/^project(bfc VERSION \([0-9.]*\).*/\1/p' CMakeLists.txt) + echo "version=v${v}" >> "$GITHUB_OUTPUT" + fi - name: Create release package (non-Windows) if: matrix.platform != 'windows' @@ -284,6 +296,7 @@ jobs: tar -czf ${PACKAGE_NAME}.tar.gz ${PACKAGE_NAME} - name: Create release package (Windows) + id: windows_package if: matrix.platform == 'windows' shell: pwsh run: | @@ -299,6 +312,16 @@ jobs: Copy-Item (Get-ChildItem -Recurse build\lib -Filter bfc.lib | Select-Object -First 1 -ExpandProperty FullName) "$pkgName\bfc.lib" Copy-Item (Get-ChildItem -Recurse build\lib -Filter bfc.dll -ErrorAction SilentlyContinue | Select-Object -First 1 -ExpandProperty FullName) "$pkgName\bfc.dll" -ErrorAction SilentlyContinue + # bfc.exe links zstd and libsodium dynamically (vcpkg x64-windows + # triplet). Without these next to it, it fails to start with + # 0xC0000135 STATUS_DLL_NOT_FOUND (#20). + $vcpkgBin = Join-Path $env:VCPKG_INSTALLATION_ROOT "installed\x64-windows\bin" + foreach ($dll in @("zstd.dll", "libsodium.dll")) { + $src = Join-Path $vcpkgBin $dll + if (-not (Test-Path $src)) { Write-Error "$dll not found in $vcpkgBin"; exit 1 } + Copy-Item $src "$pkgName\" + } + # Copy headers and docs Copy-Item include\bfc.h "$pkgName\" Copy-Item README.md "$pkgName\" @@ -308,16 +331,59 @@ jobs: @' @echo off echo Installing BFC... - copy bfc.exe "%ProgramFiles%\bfc\bfc.exe" 2>nul || ( - mkdir "%ProgramFiles%\bfc" - copy bfc.exe "%ProgramFiles%\bfc\bfc.exe" + if not exist "%ProgramFiles%\bfc" mkdir "%ProgramFiles%\bfc" || goto :fail + rem bfc.exe needs zstd.dll and libsodium.dll in the same directory + for %%f in (bfc.exe zstd.dll libsodium.dll bfc.h) do ( + copy /Y "%~dp0%%f" "%ProgramFiles%\bfc\" >nul || goto :fail ) - copy bfc.h "%ProgramFiles%\bfc\bfc.h" echo BFC installed to %ProgramFiles%\bfc + echo Add %ProgramFiles%\bfc to PATH to run bfc from any directory. + exit /b 0 + :fail + echo Installation failed. Run install.bat as Administrator. + exit /b 1 '@ | Out-File -Encoding ascii "$pkgName\install.bat" # Create ZIP Compress-Archive -Path $pkgName -DestinationPath "$pkgName.zip" + "name=$pkgName" >> $env:GITHUB_OUTPUT + + - name: Test release package with a clean PATH (Windows) + if: matrix.platform == 'windows' + shell: pwsh + run: | + # Run bfc.exe from the unpacked zip the way a user would get it: no + # vcpkg or build directory on PATH, only the system directories (#20) + $pkgName = "${{ steps.windows_package.outputs.name }}" + $dir = Join-Path $env:RUNNER_TEMP "bfc-package-test" + Remove-Item -Recurse -Force $dir -ErrorAction SilentlyContinue + Expand-Archive "$pkgName.zip" -DestinationPath $dir + $bfc = Join-Path $dir "$pkgName\bfc.exe" + $env:PATH = "C:\Windows\System32;C:\Windows" + + function Invoke-Bfc { + & $bfc @args + if ($LASTEXITCODE -ne 0) { + Write-Error ("bfc {0} failed with exit code {1} (0x{2:X8})" -f ($args -join ' '), $LASTEXITCODE, $LASTEXITCODE) + exit 1 + } + } + + Push-Location $dir + New-Item -ItemType Directory -Force pkg_data | Out-Null + "packaged bfc.exe works" | Out-File -Encoding ascii pkg_data\hello.txt + + Invoke-Bfc --version + Invoke-Bfc create -c zstd -p secret pkg.bfc pkg_data + Invoke-Bfc verify --deep -p secret pkg.bfc + New-Item -ItemType Directory -Force pkg_out | Out-Null + Invoke-Bfc extract -p secret -C pkg_out pkg.bfc + + $want = Get-Content -Raw pkg_data\hello.txt + $got = Get-Content -Raw pkg_out\pkg_data\hello.txt + if ($got -ne $want) { Write-Error "extracted content differs"; exit 1 } + Write-Output "Release package runs with a clean PATH" + Pop-Location - name: Create DEB and RPM packages (Linux only) if: matrix.platform == 'linux' @@ -460,6 +526,7 @@ jobs: hdiutil create -volname "BFC ${VERSION_NO_V}" -srcfolder dmg-contents -ov -format UDZO "${DMG_NAME}.dmg" - name: Upload Release Assets + if: startsWith(github.ref, 'refs/tags/') shell: bash env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/README.md b/README.md index de126b5..7e47ccc 100644 --- a/README.md +++ b/README.md @@ -109,6 +109,11 @@ cmake --build build --config Release ``` > **Windows notes:** +> - The release zip (`bfc--windows-x86_64.zip`) ships `bfc.exe` together with +> `zstd.dll` and `libsodium.dll`; keep them in the same directory. `install.bat` copies all +> three to `%ProgramFiles%\bfc`. The +> [Microsoft Visual C++ 2015-2022 Redistributable (x64)](https://aka.ms/vs/17/release/vc_redist.x64.exe) +> must be installed (`VCRUNTIME140.dll`); it is present on most systems already. > - Symlink creation requires Developer Mode or elevated privileges; symlinks stored in > containers are extracted as regular files on Windows without Developer Mode. > - FUSE mount (`BFC_WITH_FUSE`) is not supported on Windows. diff --git a/src/cli/cmd_create.c b/src/cli/cmd_create.c index f0b92d2..f94fef6 100644 --- a/src/cli/cmd_create.c +++ b/src/cli/cmd_create.c @@ -442,6 +442,17 @@ int cmd_create(int argc, char* argv[]) { strncpy(clean_path, input_path, sizeof(clean_path) - 1); clean_path[sizeof(clean_path) - 1] = '\0'; +#ifdef _WIN32 + // Windows also accepts '\' as a separator ("data\" in PowerShell), but + // container paths always use '/'. Without this, "data\" became the + // directory name and entries were stored as "data\/file.txt". + for (char* p = clean_path; *p; p++) { + if (*p == '\\') { + *p = '/'; + } + } +#endif + // Remove trailing slashes size_t len = strlen(clean_path); while (len > 1 && clean_path[len - 1] == '/') {