dvServerCrashDirectoryFor function
Where a server process keeps crash records for appId.
DARTVEL_CRASH_DIR when the deployment mounts one; otherwise beside the
application, in .dartvel/crashes under currentDirectory, which survives
the restart a crash causes. A process whose working directory is the root
-- a container started with no WORKDIR -- keeps them under
tempDirectory rather than writing to /.
Implementation
String dvServerCrashDirectoryFor({
required String appId,
required Map<String, String> environment,
required String currentDirectory,
required String tempDirectory,
}) {
final String declared = (environment['DARTVEL_CRASH_DIR'] ?? '').trim();
if (declared.isNotEmpty) return declared;
String cwd = currentDirectory.trim();
while (cwd.length > 1 && (cwd.endsWith('/') || cwd.endsWith(r'\'))) {
cwd = cwd.substring(0, cwd.length - 1);
}
final bool root = cwd.isEmpty ||
cwd == '/' ||
cwd == r'\' ||
RegExp(r'^[A-Za-z]:\\?$').hasMatch(cwd);
return root ? '$tempDirectory/dartvel-crashes/$appId' : '$cwd/.dartvel/crashes';
}