- Handle the different slashes correctly, also in combination (like "../..\*.txt") by using the ConvertPath() function

- Only compare file names, not the whole pathes, in the Unix code path using MatchFileNamePattern
- Small change to the Usage text

svn path=/trunk/; revision=32139
This commit is contained in:
Colin Finck 2008-02-05 15:31:12 +00:00
parent faa96fba14
commit ed5e6ac231
2 changed files with 25 additions and 20 deletions

View file

@ -375,10 +375,10 @@ bool CCabinet::IsSeparator(char Char)
char* CCabinet::ConvertPath(char* Path, bool Allocate)
/*
* FUNCTION: Replaces \ or / with the one used be the host environment
* FUNCTION: Replaces \ or / with the one used by the host environment
* ARGUMENTS:
* Path = Pointer to string with pathname
* Allocate = Specifies wther to allocate memory for the new
* Allocate = Specifies whether to allocate memory for the new
* string or to change the existing buffer
* RETURNS:
* Pointer to new path
@ -2100,17 +2100,33 @@ bool CCabinet::CreateSimpleCabinet()
while(Criteria)
{
// Store the file path with a trailing slash in szFilePath
ConvertPath(Criteria->Search, false);
#if defined(WIN32)
pszFile = strrchr(Criteria->Search, '\\');
#else
pszFile = strrchr(Criteria->Search, '/');
if(!pszFile)
pszFile = strrchr(Criteria->Search, '\\');
#endif
if(pszFile)
{
strncpy(szFilePath, Criteria->Search, pszFile - Criteria->Search + 1);
szFilePath[pszFile - Criteria->Search + 1] = 0;
// Set the pointer to the start of the file name, not the slash
pszFile++;
strncpy(szFilePath, Criteria->Search, pszFile - Criteria->Search);
szFilePath[pszFile - Criteria->Search] = 0;
}
else
{
pszFile = Criteria->Search;
#if defined(WIN32)
szFilePath[0] = 0;
#else
// needed for opendir()
strcpy(szFilePath, "./");
#endif
}
#if defined(WIN32)
// Windows: Use the easy FindFirstFile/FindNextFile API for getting all files and checking them against the pattern
@ -2144,9 +2160,6 @@ bool CCabinet::CreateSimpleCabinet()
FindClose(hFind);
#else
// Unix: Use opendir/readdir to loop through all entries, stat to check if it's a file and MatchFileNamePattern to match the file against the pattern
if(szFilePath[0] == 0)
strcpy(szFilePath, "./");
dirp = opendir(szFilePath);
if(dirp)
@ -2160,14 +2173,7 @@ bool CCabinet::CreateSimpleCabinet()
{
if(stbuf.st_mode != S_IFDIR)
{
// As we added "./" to szFilePath above, szFile might contain "./test.txt" now and Criteria->Search "test.txt".
// Therefore they won't match using MatchFileNamePattern. By using pszFile here, we can avoid this problem.
if(szFile[0] == '.' && szFile[1] == '/')
pszFile = szFile + 2;
else
pszFile = szFile;
if(MatchFileNamePattern(pszFile, Criteria->Search))
if(MatchFileNamePattern(dp->d_name, pszFile))
{
Status = AddFile(szFile);
@ -2188,7 +2194,6 @@ bool CCabinet::CreateSimpleCabinet()
closedir(dirp);
}
#endif
Criteria = Criteria->Next;

View file

@ -192,9 +192,9 @@ void CCABManager::Usage()
printf("ReactOS Cabinet Manager\n\n");
printf("CABMAN [-D | -E] [-A] [-L dir] cabinet [filename ...]\n");
printf("CABMAN [-M mode] -C dirfile [-I] [-RC file] [-P dir]\n");
printf("CABMAN [-M mode] -S cabinet filename ...\n");
printf("CABMAN [-M mode] -S cabinet filename [...]\n");
printf(" cabinet Cabinet file.\n");
printf(" filename Name of the file to extract from the cabinet.\n");
printf(" filename Name of the file to add to or extract from the cabinet.\n");
printf(" Wild cards and multiple filenames\n");
printf(" (separated by blanks) may be used.\n\n");