Skip to content

Commit c610109

Browse files
committed
fix AddItem method for file checking
1 parent 43086de commit c610109

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

Libraries/Core/Sources/ArchiveWriter.cs

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public ArchiveWriter(Format format, CompressionOption options)
126126
public void Add(string src, string name)
127127
{
128128
var e = new RawEntity(src, name);
129-
if (e.Exists) AddItem(e);
129+
if (e.Exists) AddRecursive(e);
130130
else throw new System.IO.FileNotFoundException(e.FullName);
131131
}
132132

@@ -290,21 +290,21 @@ private static string GetTarName(string src)
290290

291291
/* --------------------------------------------------------------------- */
292292
///
293-
/// AddItem
293+
/// AddRecursive
294294
///
295295
/// <summary>
296-
/// Add the specified file or directory to the archive.
296+
/// Adds the specified file or directory to the archive.
297+
/// If the specified entity is a directory, the method recursively adds
298+
/// the files or directories contained in that directory.
297299
/// </summary>
298300
///
299301
/* --------------------------------------------------------------------- */
300-
private void AddItem(RawEntity src)
302+
private void AddRecursive(RawEntity src)
301303
{
302304
Logger.Trace($"[Add] {src.RawName.Quote()}");
303305
if (Options.Filter?.Invoke(src) ?? false) return;
304306

305-
Verify(src);
306-
_items.Add(src);
307-
307+
AddItem(src);
308308
if (!src.IsDirectory) return;
309309

310310
static RawEntity make(string s, RawEntity e) =>
@@ -314,28 +314,31 @@ static RawEntity make(string s, RawEntity e) =>
314314
{
315315
var entity = make(e, src);
316316
if (Options.Filter?.Invoke(entity) ?? false) continue;
317-
_items.Add(entity);
317+
AddItem(entity);
318318
}
319319

320-
foreach (var e in Io.GetDirectories(src.FullName)) AddItem(make(e, src));
320+
foreach (var e in Io.GetDirectories(src.FullName)) AddRecursive(make(e, src));
321321
}
322322

323323
/* --------------------------------------------------------------------- */
324324
///
325-
/// Verify
325+
/// AddItem
326326
///
327327
/// <summary>
328-
/// Verifies if the specified file is accessible.
328+
/// Adds the specified file or directory to the archive.
329329
/// </summary>
330330
///
331331
/* --------------------------------------------------------------------- */
332-
private static void Verify(Entity src)
332+
private void AddItem(RawEntity src)
333333
{
334-
if (src.IsDirectory) return;
335334
try
336335
{
337-
using var stream = Io.Open(src.FullName);
338-
if (stream is null) throw new ArgumentNullException(nameof(stream));
336+
if (!src.IsDirectory)
337+
{
338+
using var stream = Io.Open(src.FullName);
339+
if (stream is null) throw new ArgumentNullException(nameof(stream));
340+
}
341+
_items.Add(src);
339342
}
340343
catch (Exception e)
341344
{

0 commit comments

Comments
 (0)