Quantcast
Channel: Rebex Q&A Forum - Recent questions and answers
Viewing all articles
Browse latest Browse all 3862

Answered: unzip: archive containing links -> exception

$
0
0

Extraction of links is not supported yet.
If you want to skip all links set MultiFileLinkMode to SkipLinks:

archive.Options.MultiFileLinkMode = LinkProcessingMode.SkipLinks;

However, you can determine the target of a link using the ZipItem.LinkTarget:

archive.GetItem("path").LinkTarget

// or

archive["path"].LinkTarget

UPDATE:

With a little effort you can extract links manually:

using (var archive = new ZipArchive(InstallationFile))
{
    // create cache of items for later use
    var items = new Dictionary<string, ZipItem>();
    foreach (var item in archive)
    {
        items.Add(item.Path, item);
    }

    // register event to handle LinkDetected problems
    archive.ProblemDetected += (s, e) =>
    {
        if (e.ProblemType == ArchiveProblemType.LinkDetected &&
            e.Operation == ArchiveOperation.Extract)
        {
            string externalPath = e.ExternalItemPath;
            string linkTarget = items[e.ArchiveItemPath].LinkTarget;

            // do what you need, e.g.:
            // var f = new UnixFileInfo(externalPath);
            // f.CreateSymbolicLink(linkTarget);                            

            // skip processing by library
            e.Action = ArchiveProblemActions.Skip;
        }
    };

    // extract all items
    var action = ActionOnExistingFiles.OverwriteAll;
    archive.ExtractAll(DatabasePath, TransferMethod.Copy, action);
}

Viewing all articles
Browse latest Browse all 3862

Trending Articles