archive icon indicating copy to clipboard operation
archive copied to clipboard

.tar.gz encode error

Open BppleMan opened this issue 2 years ago • 2 comments

archive version: 3.4.2

// with flutter_test

void main() {
  TestWidgetsFlutterBinding.ensureInitialized();

  test('temp', tempTest);
}

Future<void> tempTest() async {
  var baseDir = Directory.systemTemp.createTempSync('demo_archive');
  /*
  source
  ├── child_dir
  │   ├── child_file_1
  │   └── child_file_2
  └── child_file
  */
  var sourceDir = Directory(join(baseDir.path, 'source'));
  sourceDir.createSync();
  var childFile = File(join(sourceDir.path, 'child_file'));
  childFile.createSync();
  var childDir = Directory(join(sourceDir.path, 'child_dir'));
  childDir.createSync();
  var childFile1 = File(join(childDir.path, 'child_file_1'));
  childFile1.createSync();
  var childFile2 = File(join(childDir.path, 'child_file_2'));
  childFile2.createSync();

  var destPath = join(baseDir.path, 'dest.tar.gz');
  await TarFileEncoder().tarDirectory(sourceDir,
      compression: TarFileEncoder.GZIP, filename: destPath);
  await extractFileToDisk(destPath, join(baseDir.path, 'dest'));

  expect(
    true,
    File(join(baseDir.path, 'dest', 'source')).existsSync(),
  );
  expect(
    true,
    File(join(baseDir.path, 'dest', 'source', 'child_file')).existsSync(),
  );
  expect(
    true,
    Directory(join(baseDir.path, 'dest', 'source', 'child_dir')).existsSync(),
  );
  expect(
    true,
    File(join(baseDir.path, 'dest', 'source', 'child_dir', 'child_file_1'))
        .existsSync(),
  );
  expect(
    true,
    File(join(baseDir.path, 'dest', 'source', 'child_dir', 'child_file_2'))
        .existsSync(),
  );
}

run it with flutter_test, got error

dart:io                                                     _File.createSync
package:archive/src/io/output_file_stream.dart 27:10        new OutputFileStream
package:archive/src/io/extract_archive_to_disk.dart 181:24  extractFileToDisk

FileSystemException: Creation failed, path = '/var/folders/k4/877lnnqs0wg9lsvfkxyz8j500000gn/T/demo_archiveE0796p/dest/source/child_dir' (OS Error: Not a directory, errno = 20)

when I use other compress tool(eg: keka) encode the source dir, extractFileToDisk can correctly decode tar.gz files.

source/child_dir/ will be recognized as file, so when extracting, traversing archive.files will directly create source/child_dir as File instead of a Directory

BppleMan avatar Sep 28 '23 18:09 BppleMan

I created a PR to fix the problem #288

BppleMan avatar Oct 08 '23 09:10 BppleMan

Thanks for the fix!

brendan-duncan avatar Oct 08 '23 16:10 brendan-duncan