unrarsrc  6.1.7
About: unrar extracts, views and tests the contents of archives created with the RAR archiver.
  Fossies Dox: unrarsrc-6.1.7.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

cmdfilter.cpp
Go to the documentation of this file.
1// Return 'true' if we need to exclude the file from processing as result
2// of -x switch. If CheckInclList is true, we also check the file against
3// the include list created with -n switch.
4bool CommandData::ExclCheck(const wchar *CheckName,bool Dir,bool CheckFullPath,bool CheckInclList)
5{
6 if (CheckArgs(&ExclArgs,Dir,CheckName,CheckFullPath,MATCH_WILDSUBPATH))
7 return true;
8 if (!CheckInclList || InclArgs.ItemsCount()==0)
9 return false;
10 if (CheckArgs(&InclArgs,Dir,CheckName,CheckFullPath,MATCH_WILDSUBPATH))
11 return false;
12 return true;
13}
14
15
16bool CommandData::CheckArgs(StringList *Args,bool Dir,const wchar *CheckName,bool CheckFullPath,int MatchMode)
17{
18 wchar *Name=ConvertPath(CheckName,NULL,0);
19 wchar FullName[NM];
20 wchar CurMask[NM];
21 *FullName=0;
22 Args->Rewind();
23 while (Args->GetString(CurMask,ASIZE(CurMask)))
24 {
25 wchar *LastMaskChar=PointToLastChar(CurMask);
26 bool DirMask=IsPathDiv(*LastMaskChar); // Mask for directories only.
27
28 if (Dir)
29 {
30 // CheckName is a directory.
31 if (DirMask)
32 {
33 // We process the directory and have the directory exclusion mask.
34 // So let's convert "mask\" to "mask" and process it normally.
35
36 *LastMaskChar=0;
37 }
38 else
39 {
40 // REMOVED, we want -npath\* to match empty folders too.
41 // If mask has wildcards in name part and does not have the trailing
42 // '\' character, we cannot use it for directories.
43
44 // if (IsWildcard(PointToName(CurMask)))
45 // continue;
46 }
47 }
48 else
49 {
50 // If we process a file inside of directory excluded by "dirmask\".
51 // we want to exclude such file too. So we convert "dirmask\" to
52 // "dirmask\*". It is important for operations other than archiving
53 // with -x. When archiving with -x, directory matched by "dirmask\"
54 // is excluded from further scanning.
55
56 if (DirMask)
57 wcsncatz(CurMask,L"*",ASIZE(CurMask));
58 }
59
60#ifndef SFX_MODULE
61 if (CheckFullPath && IsFullPath(CurMask))
62 {
63 // We do not need to do the special "*\" processing here, because
64 // unlike the "else" part of this "if", now we convert names to full
65 // format, so they all include the path, which is matched by "*\"
66 // correctly. Moreover, removing "*\" from mask would break
67 // the comparison, because now all names have the path.
68
69 if (*FullName==0)
70 ConvertNameToFull(CheckName,FullName,ASIZE(FullName));
71 if (CmpName(CurMask,FullName,MatchMode))
72 return true;
73 }
74 else
75#endif
76 {
77 wchar NewName[NM+2],*CurName=Name;
78
79 // Important to convert before "*\" check below, so masks like
80 // d:*\something are processed properly.
81 wchar *CmpMask=ConvertPath(CurMask,NULL,0);
82
83 if (CmpMask[0]=='*' && IsPathDiv(CmpMask[1]))
84 {
85 // We want "*\name" to match 'name' not only in subdirectories,
86 // but also in the current directory. We convert the name
87 // from 'name' to '.\name' to be matched by "*\" part even if it is
88 // in current directory.
89 NewName[0]='.';
90 NewName[1]=CPATHDIVIDER;
91 wcsncpyz(NewName+2,Name,ASIZE(NewName)-2);
92 CurName=NewName;
93 }
94
95 if (CmpName(CmpMask,CurName,MatchMode))
96 return true;
97 }
98 }
99 return false;
100}
101
102
103
104
105#ifndef SFX_MODULE
106// Now this function performs only one task and only in Windows version:
107// it skips symlinks to directories if -e1024 switch is specified.
108// Symlinks are skipped in ScanTree class, so their entire contents
109// is skipped too. Without this function we would check the attribute
110// only directly before archiving, so we would skip the symlink record,
111// but not the contents of symlinked directory.
113{
114#ifdef _WIN_ALL
115 if ((FileAttr & FILE_ATTRIBUTE_REPARSE_POINT)!=0 &&
116 (ExclFileAttr & FILE_ATTRIBUTE_REPARSE_POINT)!=0)
117 return true;
118#endif
119 return false;
120}
121#endif
122
123
124
125
126#if !defined(SFX_MODULE)
127void CommandData::SetTimeFilters(const wchar *Mod,bool Before,bool Age)
128{
129 bool ModeOR=false,TimeMods=false;
130 const wchar *S=Mod;
131 // Check if any 'mca' modifiers are present, set OR mode if 'o' is present,
132 // skip modifiers and set S to beginning of time string. Be sure to check
133 // *S!=0, because termination 0 is a part of string for wcschr.
134 for (;*S!=0 && wcschr(L"MCAOmcao",*S)!=NULL;S++)
135 if (*S=='o' || *S=='O')
136 ModeOR=true;
137 else
138 TimeMods=true;
139
140 if (!TimeMods) // Assume 'm' if no modifiers are specified.
141 Mod=L"m";
142
143 // Set the specified time for every modifier. Be sure to check *Mod!=0,
144 // because termination 0 is a part of string for wcschr. This check is
145 // important when we set Mod to "m" above.
146 for (;*Mod!=0 && wcschr(L"MCAOmcao",*Mod)!=NULL;Mod++)
147 switch(toupperw(*Mod))
148 {
149 case 'M':
150 if (Before)
151 {
153 FileMtimeBeforeOR=ModeOR;
154 }
155 else
156 {
158 FileMtimeAfterOR=ModeOR;
159 }
160 break;
161 case 'C':
162 if (Before)
163 {
165 FileCtimeBeforeOR=ModeOR;
166 }
167 else
168 {
170 FileCtimeAfterOR=ModeOR;
171 }
172 break;
173 case 'A':
174 if (Before)
175 {
177 FileAtimeBeforeOR=ModeOR;
178 }
179 else
180 {
182 FileAtimeAfterOR=ModeOR;
183 }
184 break;
185 }
186}
187#endif
188
189
190#ifndef SFX_MODULE
191// Return 'true' if we need to exclude the file from processing.
193{
194 bool FilterOR=false;
195
196 if (FileMtimeBefore.IsSet()) // Filter present.
197 if (ftm>=FileMtimeBefore) // Condition not matched.
199 FilterOR=true; // Not matched OR filter is present.
200 else
201 return true; // Exclude file in AND mode.
202 else // Condition matched.
204 return false; // Include file in OR mode.
205
206 if (FileMtimeAfter.IsSet()) // Filter present.
207 if (ftm<FileMtimeAfter) // Condition not matched.
208 if (FileMtimeAfterOR)
209 FilterOR=true; // Not matched OR filter is present.
210 else
211 return true; // Exclude file in AND mode.
212 else // Condition matched.
213 if (FileMtimeAfterOR)
214 return false; // Include file in OR mode.
215
216 if (FileCtimeBefore.IsSet()) // Filter present.
217 if (ftc>=FileCtimeBefore) // Condition not matched.
219 FilterOR=true; // Not matched OR filter is present.
220 else
221 return true; // Exclude file in AND mode.
222 else // Condition matched.
224 return false; // Include file in OR mode.
225
226 if (FileCtimeAfter.IsSet()) // Filter present.
227 if (ftc<FileCtimeAfter) // Condition not matched.
228 if (FileCtimeAfterOR)
229 FilterOR=true; // Not matched OR filter is present.
230 else
231 return true; // Exclude file in AND mode.
232 else // Condition matched.
233 if (FileCtimeAfterOR)
234 return false; // Include file in OR mode.
235
236 if (FileAtimeBefore.IsSet()) // Filter present.
237 if (fta>=FileAtimeBefore) // Condition not matched.
239 FilterOR=true; // Not matched OR filter is present.
240 else
241 return true; // Exclude file in AND mode.
242 else // Condition matched.
244 return false; // Include file in OR mode.
245
246 if (FileAtimeAfter.IsSet()) // Filter present.
247 if (fta<FileAtimeAfter) // Condition not matched.
248 if (FileAtimeAfterOR)
249 FilterOR=true; // Not matched OR filter is present.
250 else
251 return true; // Exclude file in AND mode.
252 else // Condition matched.
253 if (FileAtimeAfterOR)
254 return false; // Include file in OR mode.
255
256 return FilterOR; // Exclude if all OR filters are not matched.
257}
258#endif
259
260
261#ifndef SFX_MODULE
262// Return 'true' if we need to exclude the file from processing.
264{
265 if (Size==INT64NDF) // If called from archive formats like bzip2, not storing the file size.
266 return false;
267 if (FileSizeLess!=INT64NDF && Size>=FileSizeLess)
268 return true;
269 if (FileSizeMore!=INT64NDF && Size<=FileSizeMore)
270 return true;
271 return false;
272}
273#endif
274
275
276
277
278// Return 0 if file must not be processed or a number of matched parameter otherwise.
279int CommandData::IsProcessFile(FileHeader &FileHead,bool *ExactMatch,int MatchType,
280 bool Flags,wchar *MatchedArg,uint MatchedArgSize)
281{
282 if (MatchedArg!=NULL && MatchedArgSize>0)
283 *MatchedArg=0;
284 bool Dir=FileHead.Dir;
285 if (ExclCheck(FileHead.FileName,Dir,false,true))
286 return 0;
287#ifndef SFX_MODULE
288 if (TimeCheck(FileHead.mtime,FileHead.ctime,FileHead.atime))
289 return 0;
290 if ((FileHead.FileAttr & ExclFileAttr)!=0 || FileHead.Dir && ExclDir)
291 return 0;
292 if (InclAttrSet && (!FileHead.Dir && (FileHead.FileAttr & InclFileAttr)==0 ||
293 FileHead.Dir && !InclDir))
294 return 0;
295 if (!Dir && SizeCheck(FileHead.UnpSize))
296 return 0;
297#endif
298 wchar *ArgName;
300 for (int StringCount=1;(ArgName=FileArgs.GetString())!=NULL;StringCount++)
301 if (CmpName(ArgName,FileHead.FileName,MatchType))
302 {
303 if (ExactMatch!=NULL)
304 *ExactMatch=wcsicompc(ArgName,FileHead.FileName)==0;
305 if (MatchedArg!=NULL)
306 wcsncpyz(MatchedArg,ArgName,MatchedArgSize);
307 return StringCount;
308 }
309 return 0;
310}
311
312
313#if !defined(SFX_MODULE)
315{
316 if (*S==0 || IsDigit(*S) || *S=='-' || *S=='+')
317 {
318 // Apply -ts, -ts1, -ts-, -ts+ to all 3 times.
319 // Handle obsolete -ts[2,3,4] as ts+.
321 if (*S=='-')
322 Mode=EXTTIME_NONE;
323 if (*S=='1')
324 Mode=EXTTIME_1S;
325 xmtime=xctime=xatime=Mode;
326 S++;
327 }
328
329 while (*S!=0)
330 {
332 if (S[1]=='-')
333 Mode=EXTTIME_NONE;
334 if (S[1]=='1')
335 Mode=EXTTIME_1S;
336 switch(toupperw(*S))
337 {
338 case 'M':
339 xmtime=Mode;
340 break;
341 case 'C':
342 xctime=Mode;
343 break;
344 case 'A':
345 xatime=Mode;
346 break;
347 case 'P':
348 PreserveAtime=true;
349 break;
350 }
351 S++;
352 }
353}
354#endif
void SetStoreTimeMode(const wchar *S)
Definition: cmdfilter.cpp:314
bool ExclCheck(const wchar *CheckName, bool Dir, bool CheckFullPath, bool CheckInclList)
Definition: cmdfilter.cpp:4
void SetTimeFilters(const wchar *Mod, bool Before, bool Age)
Definition: cmdfilter.cpp:127
static bool CheckArgs(StringList *Args, bool Dir, const wchar *CheckName, bool CheckFullPath, int MatchMode)
Definition: cmdfilter.cpp:16
bool SizeCheck(int64 Size)
Definition: cmdfilter.cpp:263
StringList InclArgs
Definition: cmddata.hpp:65
StringList ExclArgs
Definition: cmddata.hpp:64
StringList FileArgs
Definition: cmddata.hpp:63
bool TimeCheck(RarTime &ftm, RarTime &ftc, RarTime &fta)
Definition: cmdfilter.cpp:192
int IsProcessFile(FileHeader &FileHead, bool *ExactMatch, int MatchType, bool Flags, wchar *MatchedArg, uint MatchedArgSize)
Definition: cmdfilter.cpp:279
bool ExclDirByAttr(uint FileAttr)
Definition: cmdfilter.cpp:112
RarTime FileAtimeBefore
Definition: options.hpp:182
bool FileMtimeAfterOR
Definition: options.hpp:185
bool InclDir
Definition: options.hpp:100
RarTime FileAtimeAfter
Definition: options.hpp:184
RarTime FileMtimeBefore
Definition: options.hpp:182
bool FileCtimeBeforeOR
Definition: options.hpp:183
bool PreserveAtime
Definition: options.hpp:199
RarTime FileCtimeAfter
Definition: options.hpp:184
RarTime FileMtimeAfter
Definition: options.hpp:184
bool ExclDir
Definition: options.hpp:99
bool FileAtimeAfterOR
Definition: options.hpp:185
RarTime FileCtimeBefore
Definition: options.hpp:182
EXTTIME_MODE xmtime
Definition: options.hpp:196
bool FileAtimeBeforeOR
Definition: options.hpp:183
EXTTIME_MODE xatime
Definition: options.hpp:198
uint InclFileAttr
Definition: options.hpp:95
uint ExclFileAttr
Definition: options.hpp:94
int64 FileSizeLess
Definition: options.hpp:186
bool FileMtimeBeforeOR
Definition: options.hpp:183
bool InclAttrSet
Definition: options.hpp:102
int64 FileSizeMore
Definition: options.hpp:187
bool FileCtimeAfterOR
Definition: options.hpp:185
EXTTIME_MODE xctime
Definition: options.hpp:197
void SetAgeText(const wchar *TimeText)
Definition: timefn.cpp:271
void SetIsoText(const wchar *TimeText)
Definition: timefn.cpp:245
bool IsSet()
Definition: timefn.hpp:58
bool GetString(wchar *Str, size_t MaxLength)
Definition: strlist.cpp:49
void Rewind()
Definition: strlist.cpp:103
size_t ItemsCount()
Definition: strlist.hpp:24
bool CmpName(const wchar *Wildcard, const wchar *Name, int CmpMode)
Definition: match.cpp:19
@ MATCH_WILDSUBPATH
Definition: match.hpp:29
EXTTIME_MODE
Definition: options.hpp:23
@ EXTTIME_NONE
Definition: options.hpp:24
@ EXTTIME_MAX
Definition: options.hpp:24
@ EXTTIME_1S
Definition: options.hpp:24
bool IsPathDiv(int Ch)
Definition: pathfn.cpp:134
wchar * ConvertPath(const wchar *SrcPath, wchar *DestPath, size_t DestSize)
Definition: pathfn.cpp:19
bool IsFullPath(const wchar *Path)
Definition: pathfn.cpp:569
wchar * PointToLastChar(const wchar *Path)
Definition: pathfn.cpp:12
void ConvertNameToFull(const wchar *Src, wchar *Dest, size_t MaxSize)
Definition: pathfn.cpp:527
#define ASIZE(x)
Definition: rardefs.hpp:10
#define INT64NDF
Definition: rartypes.hpp:30
wchar_t wchar
Definition: rartypes.hpp:13
int64_t int64
Definition: rartypes.hpp:12
unsigned int uint
Definition: rartypes.hpp:8
static byte S[256]
Definition: rijndael.cpp:10
int wcsicompc(const wchar *s1, const wchar *s2)
Definition: strfn.cpp:242
void wcsncpyz(wchar *dest, const wchar *src, size_t maxlen)
Definition: strfn.cpp:275
void wcsncatz(wchar *dest, const wchar *src, size_t maxlen)
Definition: strfn.cpp:300
bool IsDigit(int ch)
Definition: strfn.cpp:151
RarTime atime
Definition: headers.hpp:190
int64 UnpSize
Definition: headers.hpp:193
wchar FileName[NM]
Definition: headers.hpp:184
RarTime ctime
Definition: headers.hpp:189
bool Dir
Definition: headers.hpp:223
RarTime mtime
Definition: headers.hpp:188
uint FileAttr
Definition: headers.hpp:181
int toupperw(int ch)
Definition: unicode.cpp:523