MCPcopy Create free account
hub / github.com/apache/cloudberry / pg_file_unlink

Function pg_file_unlink

contrib/adminpack/adminpack.c:401–429  ·  view source on GitHub ↗

------------------------------------ * pg_file_unlink - old version * * The superuser() check here must be kept as the library might be upgraded * without the extension being upgraded, meaning that in pre-1.1 installations * these functions could be called by any user. */

Source from the content-addressed store, hash-verified

399 * these functions could be called by any user.
400 */
401Datum
402pg_file_unlink(PG_FUNCTION_ARGS)
403{
404 char *filename;
405
406 requireSuperuser();
407
408 filename = convert_and_check_filename(PG_GETARG_TEXT_PP(0));
409
410 if (access(filename, W_OK) < 0)
411 {
412 if (errno == ENOENT)
413 PG_RETURN_BOOL(false);
414 else
415 ereport(ERROR,
416 (errcode_for_file_access(),
417 errmsg("file \"%s\" is not accessible: %m", filename)));
418 }
419
420 if (unlink(filename) < 0)
421 {
422 ereport(WARNING,
423 (errcode_for_file_access(),
424 errmsg("could not unlink file \"%s\": %m", filename)));
425
426 PG_RETURN_BOOL(false);
427 }
428 PG_RETURN_BOOL(true);
429}
430
431
432/* ------------------------------------

Callers

nothing calls this directly

Calls 4

requireSuperuserFunction · 0.70
errcode_for_file_accessFunction · 0.50
errmsgFunction · 0.50

Tested by

no test coverage detected