@cloudbitmaps/roaring 0.18.1 → 0.18.3

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.
@@ -3,7 +3,7 @@
3
3
  // src/bin/export-segments.ts
4
4
  import { randomUUID } from "node:crypto";
5
5
  import { realpathSync } from "node:fs";
6
- import { mkdir, open, rename, rm, writeFile } from "node:fs/promises";
6
+ import { lstat, mkdir, open, rename, rm, writeFile } from "node:fs/promises";
7
7
  import { join } from "node:path";
8
8
  import { pathToFileURL } from "node:url";
9
9
  import { encodeNameForPath, namespacePathPart } from "@cloudbitmaps/core/driver-kit";
@@ -3215,11 +3215,30 @@ function parseConfig(env) {
3215
3215
  const namespace = env.CR_EXPORT_NAMESPACE || void 0;
3216
3216
  return { root, out, format, namespace };
3217
3217
  }
3218
+ async function ensureOwnDirectory(out, dir) {
3219
+ await mkdir(out, { recursive: true, mode: 448 });
3220
+ try {
3221
+ await mkdir(dir, { mode: 448 });
3222
+ return;
3223
+ } catch (err) {
3224
+ if (err.code !== "EEXIST") throw err;
3225
+ }
3226
+ const found = await lstat(dir);
3227
+ const refuse = (why) => {
3228
+ throw new ValidationError3(`the export directory is not one this tool made: ${why}`);
3229
+ };
3230
+ if (found.isSymbolicLink()) refuse("a namespace directory is a symbolic link");
3231
+ if (!found.isDirectory()) refuse("a namespace path is not a directory");
3232
+ if (process.getuid !== void 0) {
3233
+ if (found.uid !== process.getuid()) refuse("a namespace directory belongs to another user");
3234
+ if ((found.mode & 63) !== 0) refuse("a namespace directory is open to group or others");
3235
+ }
3236
+ }
3218
3237
  function fsSink(out) {
3219
3238
  return {
3220
3239
  async open(ref, ext) {
3221
3240
  const dir = join(out, namespacePathPart(ref.namespace));
3222
- await mkdir(dir, { recursive: true, mode: 448 });
3241
+ await ensureOwnDirectory(out, dir);
3223
3242
  const finalPath = join(dir, `${encodeNameForPath(ref.segment)}${ext}`);
3224
3243
  const tmpPath = `${finalPath}.${randomUUID()}.part`;
3225
3244
  const handle = await open(tmpPath, "wx", 384);