@poe-platform/safe-bash 0.1.622 → 0.1.623

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -25649,7 +25649,7 @@ var Budget14 = class {
25649
25649
  if (this.members % 128 === 0) await yieldTurn(this.context.signal);
25650
25650
  }
25651
25651
  async output(value2, stderr = false) {
25652
- const bytes3 = import_buffer.Buffer.from(value2);
25652
+ const bytes3 = typeof value2 === "string" ? import_buffer.Buffer.from(value2, "utf8") : import_buffer.Buffer.from(value2);
25653
25653
  if (bytes3.length > this.limits.maxTextBytes - this.textBytes) fail("text output limit exceeded");
25654
25654
  this.textBytes += bytes3.length;
25655
25655
  await writeBytes(stderr ? this.context.stderr : this.context.stdout, bytes3, this.context.signal);
@@ -26637,6 +26637,7 @@ var longOptions = {
26637
26637
  update: "u",
26638
26638
  freshen: "f",
26639
26639
  filesync: "FS",
26640
+ "archive-comment": "z",
26640
26641
  delete: "d",
26641
26642
  include: "i",
26642
26643
  exclude: "x",
@@ -26706,8 +26707,7 @@ var reservedOptions = [
26706
26707
  "show-options",
26707
26708
  "unzip-command",
26708
26709
  "verbose",
26709
- "version",
26710
- "archive-comment"
26710
+ "version"
26711
26711
  ];
26712
26712
  function normalizeZipOption(argument2) {
26713
26713
  if (!argument2.startsWith("--") || argument2 === "--") return argument2;
@@ -26822,6 +26822,41 @@ function zipEnvironmentArguments(env, argv, limits) {
26822
26822
  return [...defaults, ...argv];
26823
26823
  }
26824
26824
 
26825
+ // packages/safe-bash/src/commands/archive/zip/comments.ts
26826
+ init_platform();
26827
+ async function readZipComment(source2, limits, signal) {
26828
+ const parts = [];
26829
+ const line = [];
26830
+ let length = 0;
26831
+ let bytes3 = 0;
26832
+ let pulls = 0;
26833
+ const append = () => {
26834
+ const zero2 = line.indexOf(0);
26835
+ const text3 = line.slice(0, zero2 < 0 ? void 0 : zero2);
26836
+ line.length = 0;
26837
+ if (text3.length === 2 && text3[0] === 46 && text3[1] === 10) return false;
26838
+ if (text3.at(-1) === 10) text3.pop();
26839
+ const separator = length || !text3.length ? 2 : 0;
26840
+ if (text3.length + separator > Math.min(limits.maxTextBytes, 65535) - length) fail("ZIP archive comment byte limit exceeded");
26841
+ if (separator) parts.push(import_buffer.Buffer.from("\r\n"));
26842
+ if (text3.length) parts.push(Uint8Array.from(text3));
26843
+ length += separator + text3.length;
26844
+ return true;
26845
+ };
26846
+ for await (const chunk of readBytes(source2, signal)) {
26847
+ if (++pulls > limits.maxPatternSteps) fail("ZIP comment input work limit exceeded");
26848
+ for (const byte of chunk) {
26849
+ if (++bytes3 > limits.maxFilesFromBytes) fail("ZIP comment input byte limit exceeded");
26850
+ line.push(byte);
26851
+ if ((byte === 10 || line.length === 65535) && !append()) return import_buffer.Buffer.concat(parts, length);
26852
+ if (bytes3 % 4096 === 0) await yieldTurn(signal);
26853
+ }
26854
+ if (pulls % 64 === 0) await yieldTurn(signal);
26855
+ }
26856
+ if (line.length) append();
26857
+ return import_buffer.Buffer.concat(parts, length);
26858
+ }
26859
+
26825
26860
  // packages/safe-bash/src/commands/archive/zip-format.ts
26826
26861
  init_platform();
26827
26862
 
@@ -27667,23 +27702,30 @@ function tokenize2(pattern, noWild, stopAtDirectories) {
27667
27702
  const negative = characters[index + 1] === "!" || characters[index + 1] === "^";
27668
27703
  if (negative) index++;
27669
27704
  const ranges = [];
27670
- let closed = false;
27671
- while (++index < characters.length) {
27672
- let first = characters[index];
27673
- if (first === "]") {
27674
- closed = true;
27675
- break;
27676
- }
27677
- if (first === "\\") first = characters[++index] ?? "";
27678
- let last = first;
27679
- if (characters[index + 1] === "-" && characters[index + 2] && characters[index + 2] !== "]") {
27680
- index += 2;
27681
- last = characters[index];
27682
- if (last === "\\") last = characters[++index] ?? "";
27705
+ const start = index + 1;
27706
+ let closing = start;
27707
+ let escaped3 = false;
27708
+ for (; closing < characters.length; closing++) {
27709
+ const current = characters[closing];
27710
+ if (escaped3) escaped3 = false;
27711
+ else if (current === "\\") escaped3 = true;
27712
+ else if (current === "]") break;
27713
+ }
27714
+ let first;
27715
+ escaped3 = characters[start] === "-";
27716
+ for (let position = start; position < closing; position++) {
27717
+ const current = characters[position];
27718
+ if (!escaped3 && current === "\\") escaped3 = true;
27719
+ else if (!escaped3 && current === "-") first = characters[position - 1].codePointAt(0);
27720
+ else {
27721
+ const last = current.codePointAt(0);
27722
+ if (characters[position + 1] !== "-") ranges.push([first ?? last, last]);
27723
+ first = void 0;
27724
+ escaped3 = false;
27683
27725
  }
27684
- ranges.push([first.codePointAt(0) ?? -1, last.codePointAt(0) ?? -1]);
27685
27726
  }
27686
- tokens2.push(closed ? { kind: "class", ranges, negative } : { kind: "never" });
27727
+ index = closing;
27728
+ tokens2.push(closing < characters.length ? { kind: "class", ranges, negative } : { kind: "never" });
27687
27729
  } else tokens2.push({ kind: "literal", value: character });
27688
27730
  }
27689
27731
  return tokens2;
@@ -27824,6 +27866,7 @@ async function parse12(scope, limits) {
27824
27866
  let test = false;
27825
27867
  let mustMatch = false;
27826
27868
  let filesync = false;
27869
+ let archiveComment = false;
27827
27870
  let fromDate;
27828
27871
  let beforeDate;
27829
27872
  let descriptors = false;
@@ -27877,6 +27920,7 @@ async function parse12(scope, limits) {
27877
27920
  filesync = true;
27878
27921
  offset++;
27879
27922
  } else if (flag === "q") quiet = true;
27923
+ else if (flag === "z") archiveComment = true;
27880
27924
  else if (flag === "j") junkPaths = true;
27881
27925
  else if (flag === "X") {
27882
27926
  metadata3 = argument2[offset + 1] === "-" ? "all" : "strip";
@@ -27995,7 +28039,7 @@ async function parse12(scope, limits) {
27995
28039
  }
27996
28040
  if (recursivePatterns && !names.length && !operands.length) throw new ZipFailure(16, "Invalid command arguments", "nothing to select from");
27997
28041
  if (filesync && action !== "add") throw new ZipFailure(16, "Invalid command arguments", "can't use -d, -f, -u, -U, or -g with filesync -FS\n");
27998
- return { args, action, archive, output: output2, recursive, recursivePatterns, noWild, stopAtDirectories, quiet, junkPaths, omitDirectories, storeLinks, test, mustMatch, filesync, fromDate, beforeDate, descriptors, zip64, metadata: metadata3, includes, excludes, level, method, suffixes, operands: [...names, ...operands], firstOperand };
28042
+ return { args, action, archive, output: output2, recursive, recursivePatterns, noWild, stopAtDirectories, quiet, junkPaths, omitDirectories, storeLinks, test, mustMatch, filesync, archiveComment, fromDate, beforeDate, descriptors, zip64, metadata: metadata3, includes, excludes, level, method, suffixes, operands: [...names, ...operands], firstOperand };
27999
28043
  }
28000
28044
  function memberName(path, limits) {
28001
28045
  if (path.startsWith("//") && !path.startsWith("///")) fail("UNC source paths are unsupported");
@@ -28233,6 +28277,8 @@ async function prepare(scope, parsed, budget) {
28233
28277
  }
28234
28278
  }
28235
28279
  };
28280
+ const editComment = parsed.archiveComment && parsed.action !== "delete" && parsed.action !== "copy";
28281
+ if (parsed.archiveComment && parsed.action === "copy" && !parsed.quiet) await budget.output(" zip warning: can't set method, move, recurse, or comments with copy mode.\n");
28236
28282
  if (parsed.action === "copy") {
28237
28283
  const operands = new Selection(parsed.operands, limits, context2.signal, { noWild: parsed.noWild, stopAtDirectories: parsed.stopAtDirectories });
28238
28284
  for (const entry of archive.entries) {
@@ -28242,7 +28288,7 @@ async function prepare(scope, parsed, budget) {
28242
28288
  }
28243
28289
  }
28244
28290
  } else if (parsed.action === "delete") {
28245
- if (!parsed.quiet && parsed.recursive) await budget.output(" zip warning: invalid option(s) used with -d; ignored.\n");
28291
+ if (!parsed.quiet && (parsed.recursive || parsed.archiveComment)) await budget.output(" zip warning: invalid option(s) used with -d; ignored.\n");
28246
28292
  if (!parsed.quiet && !archive.entries.length) await budget.output(` zip warning: ${parsed.archive} not found or empty
28247
28293
  `);
28248
28294
  const operands = new Selection(parsed.recursivePatterns ? [] : parsed.operands, limits, context2.signal, { noWild: parsed.noWild, stopAtDirectories: parsed.stopAtDirectories });
@@ -28275,8 +28321,8 @@ async function prepare(scope, parsed, budget) {
28275
28321
  return { kind: "current" };
28276
28322
  }
28277
28323
  }
28278
- if (!selected.size && (parsed.action === "freshen" || parsed.action === "update" && (existing2 || !parsed.includes.length))) return void 0;
28279
- if (!selected.size && !deleted.size && (parsed.action === "delete" || parsed.action === "copy" || parsed.recursivePatterns || parsed.fromDate !== void 0 || parsed.beforeDate !== void 0 || !parsed.includes.length)) {
28324
+ if (!selected.size && !(editComment && archive.entries.length) && (parsed.action === "freshen" || parsed.action === "update" && (existing2 || !parsed.includes.length))) return void 0;
28325
+ if (!selected.size && !deleted.size && !(editComment && archive.entries.length) && (parsed.action === "delete" || parsed.action === "copy" || parsed.recursivePatterns || parsed.fromDate !== void 0 || parsed.beforeDate !== void 0 || !parsed.includes.length)) {
28280
28326
  const detail = parsed.action !== "delete" && parsed.recursive && parsed.firstOperand >= 0 ? `try: zip ${parsed.args.slice(0, parsed.firstOperand).join(" ")} . -i ${parsed.args.slice(parsed.firstOperand).join(" ")}` : parsed.archive;
28281
28327
  throw new ZipFailure(12, "Nothing to do!", detail);
28282
28328
  }
@@ -28326,8 +28372,23 @@ async function prepare(scope, parsed, budget) {
28326
28372
  append(entry, false);
28327
28373
  }
28328
28374
  if (!entries2.length) queue(" zip warning: zip file empty\n");
28329
- if (!publication) return { kind: "stream", archive: { entries: entries2, comment: archive.comment }, progress };
28330
- const bytes3 = await writeZipArchive({ entries: entries2, comment: archive.comment }, limits, context2.signal, false, parsed.zip64 === true);
28375
+ let comment2 = archive.comment;
28376
+ if (editComment) {
28377
+ for (const message3 of progress) await budget.output(message3);
28378
+ progress.length = 0;
28379
+ progressBytes = 0;
28380
+ if (!parsed.quiet) {
28381
+ if (comment2.length) {
28382
+ await budget.output("current zip file comment is:\n");
28383
+ await budget.output(comment2);
28384
+ if (comment2.at(-1) !== 10) await budget.output("\n");
28385
+ }
28386
+ await budget.output("enter new zip file comment (end with .):\n");
28387
+ }
28388
+ comment2 = await readZipComment(scope.stdin, limits, context2.signal);
28389
+ }
28390
+ if (!publication) return { kind: "stream", archive: { entries: entries2, comment: comment2 }, progress };
28391
+ const bytes3 = await writeZipArchive({ entries: entries2, comment: comment2 }, limits, context2.signal, false, parsed.zip64 === true);
28331
28392
  if (parsed.test && parsed.archive !== "-") {
28332
28393
  for (const message3 of progress) await budget.output(message3);
28333
28394
  progress.length = 0;