{"record":{"id":"6f8a2648ceb0e369","repo":"nextcloud/server","slug":"location-location-is-not-valid-cannot-open-loc","errorCode":null,"errorMessage":"Location <$location> is not valid. Cannot open location for write operation.","messagePattern":"Location <\\$location> is not valid\\. Cannot open location for write operation\\.","errorType":"console","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"apps/dav/lib/Command/ExportCalendar.php","lineNumber":83,"sourceCode":"\t\tif ($calendars === []) {\n\t\t\tthrow new InvalidArgumentException(\"Calendar <$calendarId> not found.\");\n\t\t}\n\t\t$calendar = $calendars[0];\n\t\tif (!$calendar instanceof ICalendarExport) {\n\t\t\tthrow new InvalidArgumentException(\"Calendar <$calendarId> does not support exporting\");\n\t\t}\n\t\t// construct options object\n\t\t$options = new CalendarExportOptions();\n\t\t// evaluate if provided format is supported\n\t\tif (!in_array($format, ExportService::FORMATS, true)) {\n\t\t\tthrow new InvalidArgumentException(\"Format <$format> is not valid.\");\n\t\t}\n\t\t$options->setFormat($format);\n\t\t// evaluate if a valid location was given and is usable otherwise output to stdout\n\t\tif ($location !== null) {\n\t\t\t$handle = fopen($location, 'wb');\n\t\t\tif ($handle === false) {\n\t\t\t\tthrow new InvalidArgumentException(\"Location <$location> is not valid. Cannot open location for write operation.\");\n\t\t\t}\n\n\t\t\tforeach ($this->exportService->export($calendar, $options) as $chunk) {\n\t\t\t\tfwrite($handle, $chunk);\n\t\t\t}\n\t\t\tfclose($handle);\n\t\t} else {\n\t\t\tforeach ($this->exportService->export($calendar, $options) as $chunk) {\n\t\t\t\t$output->writeln($chunk);\n\t\t\t}\n\t\t}\n\n\t\treturn self::SUCCESS;\n\t}\n}\n","sourceCodeStart":65,"sourceCodeEnd":99,"githubUrl":"https://github.com/nextcloud/server/blob/ecdeb153ffdf227235c9a7e2d13dbe0f9c817bc3/apps/dav/lib/Command/ExportCalendar.php#L65-L99","documentation":"InvalidArgumentException thrown by occ dav:export-calendar (apps/dav/lib/Command/ExportCalendar.php:83) when fopen($location, 'wb') fails - the --location path cannot be opened for writing. PHP's fopen returns false for missing parent directories, no write permission, or an invalid scheme.","triggerScenarios":"occ dav:export-calendar alice personal --location=/path/with/no/dir/out.ics, or a path owned by another user, or a directory given instead of a file, or open_basedir restrictions for the occ PHP process.","commonSituations":"Typos in the directory part; running occ as www-data while writing to /root or a user home; relative paths resolved from an unexpected cwd; open_basedir limits.","solutions":["mkdir -p the parent directory and make it writable by the occ user (usually www-data)","Use an absolute path in a writable location such as /tmp/out.ics","Verify with sudo -u www-data test -w <dir>; omit --location to stream to stdout and redirect instead"],"exampleFix":"# before\nocc dav:export-calendar alice personal --location=/srv/exports/out.ics   # dir missing\n# after\nmkdir -p /srv/exports && chown www-data: /srv/exports\nocc dav:export-calendar alice personal --location=/srv/exports/out.ics\n# or: occ dav:export-calendar alice personal > out.ics","handlingStrategy":"validation","validationCode":"// shell: verify writability before invoking occ\n$dir = dirname($location);\nif (!is_dir($dir) || !is_writable($dir)) {\n    throw new RuntimeException(\"Cannot write to $dir\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use absolute paths for --location","Pre-create output directories and chown them to the occ user (www-data)","Prefer stdout redirection when unsure of filesystem permissions"],"tags":["occ","cli","export","calendar","file-permissions","fopen","invalid-path"],"backgroundTag":"file-open-failed","analyzedSha":"ecdeb153ffdf227235c9a7e2d13dbe0f9c817bc3","analyzedAt":"2026-08-17T01:36:13.386Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}