Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ EXTRA_DIST = PORTING ROADMAP \
tests/bug44.tar.gz \
tests/bug128-parfiles.tar.gz \
tests/bug190.tar.gz \
tests/flatdata-filelist.txt \
tests/subdirdata-filelist.txt \
tests/subdirdata-partial-filelist.txt \
tests/subdirdata-folder-filelist.txt \
tests/testfuncs.ps1 \
tests/build_unit_tests.ps1 \
tests/run_tests.ps1 \
Expand Down Expand Up @@ -152,6 +156,14 @@ EXTRA_DIST = PORTING ROADMAP \
tests/test34.ps1 \
tests/test35 \
tests/test35.ps1 \
tests/test36 \
tests/test36.ps1 \
tests/test37 \
tests/test37.ps1 \
tests/test38 \
tests/test38.ps1 \
tests/test39 \
tests/test39.ps1 \
tests/unit_tests \
tests/unit_tests.ps1

Expand Down Expand Up @@ -227,6 +239,10 @@ TESTS = tests/test1 \
tests/test33 \
tests/test34 \
tests/test35 \
tests/test36 \
tests/test37 \
tests/test38 \
tests/test39 \
tests/utf8_test \
tests/unit_tests

Expand Down
75 changes: 60 additions & 15 deletions src/commandline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include<iostream>
#include<algorithm>
#include "commandline.h"

#include <fstream> //ADDED for @FILELIST FUNCTIONALY

#ifdef _MSC_VER
#ifdef _DEBUG
Expand Down Expand Up @@ -140,6 +140,8 @@ void CommandLine::usage(void)
" -n<n> : Number of recovery files (max 31) (don't use both -n and -l)\n"
" -R : Recurse into subdirectories\n"
" (Be aware of wildcard shell expansion)\n"
" @ : Process a listing of files specified in a text file \n"
" (eg. @filelist.txt) \n"
"\n";
std::cout <<
"Example:\n"
Expand Down Expand Up @@ -289,10 +291,11 @@ bool CommandLine::ReadArgs(int argc, const char * const *argv)
{
if (argv[0][0])
{
if (options && argv[0][0] != '-')
//MODIFIED FOR @FILELIST FUNCTIONALITY
if (options && argv[0][0] != '-' && argv[0][0] != '@')
options = false;

if (options)
//MODIFIED FOR @FILELIST FUNCTIONALITY
if (options && argv[0][0] == '-')
{
switch (argv[0][1])
{
Expand Down Expand Up @@ -855,6 +858,51 @@ bool CommandLine::ReadArgs(int argc, const char * const *argv)
}
}
}
//START SECTION FOR ADDING @FILELIST FUNCTIONALITY
else if (argv[0][0] == '@') // Handle list files
{
// 1. Check if the '@' is followed by a filename
if (argv[0][1] == '\0')
{
std::cerr << "No filename specified after '@' symbol." << std::endl;
return false;
}

std::ifstream listfile(&argv[0][1]);
if (!listfile.is_open())
{
std::cerr << "Could not open list file: " << &argv[0][1] << std::endl;
return false;
}

std::string line;
while (std::getline(listfile, line))
{
// 2. Trim whitespace or skip whitespace-only lines
// This finds the first non-whitespace character
size_t first = line.find_first_not_of(" \t\r\n");
if (first == std::string::npos)
continue; // Line is empty or only whitespace

// 3. Removed the 'parfilename.length() == 0' block.
// All files in the list are now treated as source files.

std::string lpath, lname;
DiskFile::SplitFilename(line, lpath, lname);
std::unique_ptr< std::list<std::string> > filenames(
DiskFile::FindFiles(lpath, lname, recursive)
);

if (filenames)
{
for (auto const& fn : *filenames)
{
rawfilenames.push_back(DiskFile::GetCanonicalPathname(fn));
}
}
}
} //END SECTION FOR ADDING @filelist FUNCTIONALITY

else if (parfilename.length() == 0)
{
std::string filename = argv[0];
Expand All @@ -871,20 +919,17 @@ bool CommandLine::ReadArgs(int argc, const char * const *argv)
std::string path;
std::string name;
DiskFile::SplitFilename(argv[0], path, name);
std::unique_ptr< std::list<std::string> > filenames(
DiskFile::FindFiles(path, name, recursive)
);
std::unique_ptr< std::list<std::string> > filenames(
DiskFile::FindFiles(path, name, recursive)
);

std::list<std::string>::iterator fn = filenames->begin();
while (fn != filenames->end())
if (filenames)
{
// Convert filename from command line into a full path + filename
std::string filename = DiskFile::GetCanonicalPathname(*fn);
rawfilenames.push_back(filename);
++fn;
for (auto const& fn : *filenames)
{
rawfilenames.push_back(DiskFile::GetCanonicalPathname(fn));
}
}

// delete filenames; Taken care of by unique_ptr<>
}
}

Expand Down
10 changes: 10 additions & 0 deletions tests/flatdata-filelist.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
test-0.data
test-1.data
test-2.data
test-3.data
test-4.data
test-5.data
test-6.data
test-7.data
test-8.data
test-9.data
10 changes: 10 additions & 0 deletions tests/subdirdata-filelist.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
subdir1/test-0.data
subdir2/test-1.data
subdir1/test-2.data
subdir2/test-3.data
subdir1/test-4.data
subdir2/test-5.data
subdir1/test-6.data
subdir2/test-7.data
subdir1/test-8.data
subdir2/test-9.data
6 changes: 6 additions & 0 deletions tests/subdirdata-folder-filelist.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
subdir1
subdir2/test-1.data
subdir2/test-3.data
subdir2/test-5.data
subdir2/test-7.data
subdir2/test-9.data
6 changes: 6 additions & 0 deletions tests/subdirdata-partial-filelist.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
subdir1/test-0.data
subdir2/test-1.data
subdir1/test-2.data
subdir2/test-3.data
subdir1/test-4.data
subdir2/test-5.data
54 changes: 54 additions & 0 deletions tests/test36
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/bin/sh

execdir="$PWD"

# valgrind tests memory usage.
# wine allow for windows testing on linux
if [ -n "${PARVALGRINDOPTS+set}" ]
then
PARBINARY="valgrind $PARVALGRINDOPTS $execdir/par2"
elif [ "`which wine`" != "" ] && [ -f "$execdir/par2.exe" ]
then
PARBINARY="wine $execdir/par2.exe"
else
PARBINARY="$execdir/par2"
fi


if [ -z "$srcdir" ] || [ "." = "$srcdir" ]; then
srcdir="$PWD"
TESTDATA="$srcdir/tests"
else
srcdir="$PWD/$srcdir"
TESTDATA="$srcdir/tests"
fi

TESTROOT="$PWD"

testname=$(basename $0)
rm -f "$testname.log"
rm -rf "run$testname"

mkdir "run$testname" && cd "run$testname" || { echo "ERROR: Could not change to test directory" ; exit 1; } >&2

tar -xzf "$TESTDATA/flatdata.tar.gz" || { echo "ERROR: Could not extract data test files" ; exit 1; } >&2

banner="Testing flat data par2 creation with filelist form file"
dashes=`echo "$banner" | sed s/./-/g`

echo $dashes
echo $banner
echo $dashes

# get @flatdata-filelist.txt
cp "$TESTDATA/flatdata-filelist.txt" ./

$PARBINARY c recovery.par2 @flatdata-filelist.txt || { echo "ERROR: failed to create parchive from filelist" ; exit 1; } >&2
$PARBINARY v recovery.par2 || { echo "ERROR: failed to verify parchive created from filelist" ; exit 1; } >&2

echo "Sucessfully created and verified par2 recovery with filelist from file"

cd "$TESTROOT"
rm -rf "run$testname"

exit 0
37 changes: 37 additions & 0 deletions tests/test36.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env pwsh
# Test 34: Rename-only mode skips damaged files

$ErrorActionPreference = "Stop"

# Source common test functions
. (Join-Path $PSScriptRoot "testfuncs.ps1")

$testname = [System.IO.Path]::GetFileNameWithoutExtension($MyInvocation.MyCommand.Name)

try {
Initialize-Test -TestName $testname

Expand-TarGz -Archive (Join-Path $TESTDATA "flatdata.tar.gz") -Destination "."
Copy-Item (Join-Path $TESTDATA "flatdata-filelist.txt") "."

Write-Banner "Testing flat data par2 creation with filelist from file"

$exitCode = Invoke-Par2 -Arguments @("c", "recovery.par2", "@flatdata-filelist.txt")
if ($exitCode -ne 0) {
Exit-TestWithError "failed to create parchive from filelist"
}

$exitCode = Invoke-Par2 -Arguments @("r", "recovery.par2")
if ($exitCode -ne 0) {
Exit-TestWithError "failed to verify parchive created from filelist"
}

Write-Host "Sucessfully created and verified par2 recovery with filelist from file"
Complete-Test
exit 0
}
catch {
Write-Host "ERROR: $_" -ForegroundColor Red
Complete-Test
exit 1
}
53 changes: 53 additions & 0 deletions tests/test37
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/bin/sh

execdir="$PWD"

# valgrind tests memory usage.
# wine allow for windows testing on linux
if [ -n "${PARVALGRINDOPTS+set}" ]
then
PARBINARY="valgrind $PARVALGRINDOPTS $execdir/par2"
elif [ "`which wine`" != "" ] && [ -f "$execdir/par2.exe" ]
then
PARBINARY="wine $execdir/par2.exe"
else
PARBINARY="$execdir/par2"
fi


if [ -z "$srcdir" ] || [ "." = "$srcdir" ]; then
srcdir="$PWD"
TESTDATA="$srcdir/tests"
else
srcdir="$PWD/$srcdir"
TESTDATA="$srcdir/tests"
fi

TESTROOT="$PWD"

testname=$(basename $0)
rm -f "$testname.log"
rm -rf "run$testname"

mkdir "run$testname" && cd "run$testname" || { echo "ERROR: Could not change to test directory" ; exit 1; } >&2

tar -xzf "$TESTDATA/subdirdata.tar.gz" || { echo "ERROR: Could not extract data test files" ; exit 1; } >&2

banner="Testing subdir data par2 creation with filelist form file"
dashes=`echo "$banner" | sed s/./-/g`

echo $dashes
echo $banner
echo $dashes

cp "$TESTDATA/subdirdata-filelist.txt" ./

$PARBINARY c recovery.par2 @subdirdata-filelist.txt || { echo "ERROR: failed to create parchive from filelist" ; exit 1; } >&2
$PARBINARY v recovery.par2 || { echo "ERROR: failed to verify parchive created from filelist" ; exit 1; } >&2

echo "Sucessfully created and verified par2 recovery with filelist from file"

cd "$TESTROOT"
rm -rf "run$testname"

exit 0
37 changes: 37 additions & 0 deletions tests/test37.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env pwsh
# Test 34: Rename-only mode skips damaged files

$ErrorActionPreference = "Stop"

# Source common test functions
. (Join-Path $PSScriptRoot "testfuncs.ps1")

$testname = [System.IO.Path]::GetFileNameWithoutExtension($MyInvocation.MyCommand.Name)

try {
Initialize-Test -TestName $testname

Expand-TarGz -Archive (Join-Path $TESTDATA "subdirdata.tar.gz") -Destination "."
Copy-Item (Join-Path $TESTDATA "subdirdata-filelist.txt") "."

Write-Banner "Testing subdir data par2 creation with filelist form file"

$exitCode = Invoke-Par2 -Arguments @("c", "recovery.par2", "@subdirdata-filelist.txt")
if ($exitCode -ne 0) {
Exit-TestWithError "failed to create parchive from filelist"
}

$exitCode = Invoke-Par2 -Arguments @("r", "recovery.par2")
if ($exitCode -ne 0) {
Exit-TestWithError "failed to verify parchive created from filelist"
}

Write-Host "Sucessfully created and verified par2 recovery with filelist from file"
Complete-Test
exit 0
}
catch {
Write-Host "ERROR: $_" -ForegroundColor Red
Complete-Test
exit 1
}
Loading
Loading