Cocoa App folder in zip file does not work as application when copied in C#

The ZIP file (sample.zip) contains the Cocoa application file (sample.app). If you copy the ZIP file (sample-new.zip) and extract it using the following code, the contents of the extracted folder (sample.app) are the same when compared by diff. However it is not recognized as an Cocoa application. 

sample.app is converted to AppleDouble format in advance using ditto -c-k.

using System.IO.Compression;

var zipFileName = "sample.zip";
var newZipFileName = "sample-new.zip";
var zipPath = $@"./data/{zipFileName}";
var newZipPath = $@"./data/{newZipFileName}";

// open ZIP file.
using (var archive = ZipFile.Open(zipPath, ZipArchiveMode.Read))
using (var memoryStream = new MemoryStream())
using (var newArchive = new ZipArchive(memoryStream, ZipArchiveMode.Create, true))
{
    foreach (var entry in archive.Entries)
    {
        var newEntry = newArchive.CreateEntry(entry.FullName);
        using var archiveEntry = entry.Open();
        using var newArchiveEntry = newEntry.Open();
        archiveEntry.CopyTo(newArchiveEntry);
    }
    newArchive.Dispose();

    using var fileStream = new FileStream(newZipPath, FileMode.Create);
    memoryStream.Seek(0, SeekOrigin.Begin);
    // create new zip file
    memoryStream.CopyTo(fileStream);
}

I would like to know why it is not recognized as an application even though the files in the folder are the same.

This sample.app will of course work if copied in Finder app, but I don't know if it's because the Application file is missing some specification or why copying in code doesn't work.

Thanks.

Answered by fujimori in 707001022

I found that I needed to add execute permissions (chmod +x) to the MacOS folder. I added ExternalAttributes property on the Entry class when copying a ZIP file. This is limited to Mac and Linux (not Windows) due to the file format.

Accepted Answer

I found that I needed to add execute permissions (chmod +x) to the MacOS folder. I added ExternalAttributes property on the Entry class when copying a ZIP file. This is limited to Mac and Linux (not Windows) due to the file format.

Cocoa App folder in zip file does not work as application when copied in C#
 
 
Q