addFilesByDirectory method

void addFilesByDirectory({
  1. required Directory directory,
  2. required Directory directoryBase,
  3. required ArchiveGeneralLibOptions archiveGeneralLibOptions,
})

archive directory

Implementation

void addFilesByDirectory({
  required Directory directory,
  required Directory directoryBase,
  required ArchiveGeneralLibOptions archiveGeneralLibOptions,
}) {
  final List<String> fileSystemEntityIgnores =
      (archiveGeneralLibOptions.isUseFileSystemEntityIgnore)
          ? archiveGeneralLibOptions.fileSystemEntityIgnore.toGlob()
          : [];
  if (archiveGeneralLibOptions.isUseFileSystemEntityIgnore) {
    for (final element in FileSystemEntityIgnore.getFileIgnoresByDirectory(
        currentPath: directory.uri.toFilePath())) {
      if (fileSystemEntityIgnores.contains(element) == false) {
        fileSystemEntityIgnores.add(element);
      }
    }
  }
  final List<RegExp> fileSystemEntityIgnoresRegexp =
      fileSystemEntityIgnores.map((e) => RegExp(e)).toList();

  for (final element in directory.listSync()) {
    if (fileSystemEntityIgnoresRegexp.globContains(element.path)) {
      continue;
    }
    if (element is Directory) {
      addFilesByDirectory(
        directory: element,
        directoryBase: directoryBase,
        archiveGeneralLibOptions: archiveGeneralLibOptions.copyWith(
          fileSystemEntityIgnore: fileSystemEntityIgnores.join("\n"),
        ),
      );
    } else if (element is File) {
      addFile(
        fileSystemEntity: element,
        name: path_package.relative(element.uri.toFilePath(),
            from: directoryBase.uri.toFilePath()),
      );
    }
  }
  fileSystemEntityIgnores.clear();
  fileSystemEntityIgnoresRegexp.clear();
}