"use strict";
/* Socket Lib - Built with esbuild */
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var directory_exports = {};
__export(directory_exports, {
  ensureIpcDirectory: () => ensureIpcDirectory
});
module.exports = __toCommonJS(directory_exports);
var import_node_process = __toESM(require("node:process"));
var import_error = require("../primordials/error");
var import_internal = require("./_internal");
async function ensureIpcDirectory(filePath) {
  const fs = (0, import_internal.getFs)();
  const path = (0, import_internal.getPath)();
  const dir = path.dirname(filePath);
  await fs.promises.mkdir(dir, { recursive: true, mode: 448 });
  if (import_node_process.default.platform === "win32") {
    return;
  }
  const stats = await fs.promises.lstat(dir);
  if (!stats.isDirectory()) {
    throw new import_error.ErrorCtor(`IPC path is not a directory: ${dir}`);
  }
  const getuid = import_node_process.default.getuid;
  const ownUid = typeof getuid === "function" ? getuid.call(import_node_process.default) : -1;
  if (ownUid !== -1 && stats.uid !== ownUid) {
    throw new import_error.ErrorCtor(
      `IPC directory ${dir} is owned by another user (uid ${stats.uid}); refusing to use it.`
    );
  }
  const mode = stats.mode & 511;
  if ((mode & 63) !== 0) {
    await fs.promises.chmod(dir, 448);
  }
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  ensureIpcDirectory
});
