Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot access symlinks in archives #3232

Closed
irbull opened this issue Mar 3, 2023 · 1 comment · Fixed by #3686
Closed

Cannot access symlinks in archives #3232

irbull opened this issue Mar 3, 2023 · 1 comment · Fixed by #3686

Comments

@irbull
Copy link
Contributor

irbull commented Mar 3, 2023

When traversing the contents of a Tar Archive, there doesn't appear to be a way to access the reference to which a sym link points. The TarEntry structure indicates that the type is symlink, but there is no other metadata with information about where the sym link points.

import { join } from "https://deno.land/[email protected]/path/mod.ts";
import { ensureDir, ensureFile } from "https://deno.land/[email protected]/fs/mod.ts";
import { copy } from "https://deno.land/[email protected]/streams/mod.ts";
import { Untar } from "https://deno.land/[email protected]/archive/mod.ts";

export async function extractTarArchive(archive: string, destination: string) {
  const reader = await Deno.open(archive, { read: true });
  const untar = new Untar(reader);
  for await (const entry of untar) {
    if (entry.type === "symlink") {
      console.log(entry);
      continue;
    }
    if (entry.type === "directory") {
      await ensureDir(join(destination, entry.fileName));
      continue;
    }
    await ensureFile(join(destination, entry.fileName));
    const file = await Deno.open(join(destination, entry.fileName), {
      write: true,
    });
    await copy(entry, file);
  }
}

extractTarArchive("tarball.tar", "output_folder");

Here is a snippet that will attempt to read the contents of a Tar Archive. If it encounters a symlink it prints the metadata, but there doesn't appear to be a way to see what the sym link points too. In the case of a symlink I see this:

TarEntry {
  fileName: "folder/linked_file.txt",
  fileMode: 493,
  mtime: 1677876636,
  uid: 501,
  gid: 20,
  owner: "irbull",
  group: "staff",
  type: "symlink",
  fileSize: 0
}

This link_file.txt should point to file.txt. I've attached a tar archive that includes a sym link. (sorry, I had to zip the tar archive, as GitHub doesn't accept .tar files.)

tarball.tar.zip

@lucacasonato lucacasonato transferred this issue from denoland/deno Mar 6, 2023
@cwirving
Copy link
Contributor

cwirving commented Oct 3, 2023

I had to modify a copy of archive/untar.ts to expose the linkName property on the TarEntry type in order to work around this issue (extracting tar files containing symbolic links). If there is interest (I know that there is a lot of talk about changing the archive module to use streams -- #1985 -- so changes to the old version may not be welcome), I could contribute it back here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants