writeGlobalStore static method

String? writeGlobalStore(
  1. Map<String, dynamic> values
)

Writes values to the machine-wide store with owner-only permissions.

Returns the path written, or null when the write failed.

Implementation

static String? writeGlobalStore(Map<String, dynamic> values) {
  final file = globalStore;
  try {
    file.parent.createSync(recursive: true);
    file.writeAsStringSync(
      const JsonEncoder.withIndent('  ').convert(values),
    );
    // The file holds an API key; keep it out of reach of other accounts.
    // A missing chmod is not a reason to fail — the file is already written.
    if (!Platform.isWindows) {
      try {
        Process.runSync('chmod', ['600', file.path]);
      } on ProcessException {
        // Nothing to do; the store is usable, just not locked down.
      }
    }
    return file.path;
  } on FileSystemException {
    return null;
  }
}