writeEncryptedPlacesToPod function
Write encrypted places to Pod. Returns (success, dirCreated) tuple.
Note: This function uses relative paths for writePod() which expects paths relative to the data directory (e.g., "encrypted_data/places.json"). The inheritKeyFrom parameter also uses a relative directory path. This differs from ensureEncryptedPlacesDir() which uses full URLs.
Implementation
Future<(bool success, bool dirCreated)> writeEncryptedPlacesToPod(
List<Place> places,
bool directoryVerified,
) async {
try {
// Ensure directory exists.
final (dirExists, dirCreated) = await ensureEncryptedPlacesDir(
directoryVerified,
);
if (!dirExists) {
return (false, false);
}
// Use relative paths (writePod uses PathType.relativeToData by default)
final filePath = getEncryptedPlacesFilePath();
final dirPath = getEncryptedPlacesDirPath();
// Convert places to JSON.
final jsonList = places.map((p) => p.toJson()).toList();
final jsonContent = jsonEncode(jsonList);
// Write encrypted file with key inheritance from directory
// Note: When using inheritKeyFrom, the encryption is handled by the
// directory's key, not by a file-specific individual key. So we set
// encrypted: false to avoid the "encryption status changed" dialog.
// The file will still be encrypted via the inherited directory key.
await writePod(
filePath,
jsonContent,
encrypted: false,
overwrite: true,
inheritKeyFrom: dirPath,
);
// writePod returns void in 0.9.x, assume success if no exception.
return (true, dirCreated);
} catch (e) {
debugPrint('Error writing encrypted places: $e');
return (false, false);
}
}