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

Function pg_file_rename_internal

contrib/adminpack/adminpack.c:308–391  ·  view source on GitHub ↗

------------------------------------ * pg_file_rename_internal - Workhorse for pg_file_rename functions. * * This handles the actual work for pg_file_rename. */

Source from the content-addressed store, hash-verified

306 * This handles the actual work for pg_file_rename.
307 */
308static bool
309pg_file_rename_internal(text *file1, text *file2, text *file3)
310{
311 char *fn1,
312 *fn2,
313 *fn3;
314 int rc;
315
316 fn1 = convert_and_check_filename(file1);
317 fn2 = convert_and_check_filename(file2);
318
319 if (file3 == NULL)
320 fn3 = NULL;
321 else
322 fn3 = convert_and_check_filename(file3);
323
324 if (access(fn1, W_OK) < 0)
325 {
326 ereport(WARNING,
327 (errcode_for_file_access(),
328 errmsg("file \"%s\" is not accessible: %m", fn1)));
329
330 return false;
331 }
332
333 if (fn3 && access(fn2, W_OK) < 0)
334 {
335 ereport(WARNING,
336 (errcode_for_file_access(),
337 errmsg("file \"%s\" is not accessible: %m", fn2)));
338
339 return false;
340 }
341
342 rc = access(fn3 ? fn3 : fn2, W_OK);
343 if (rc >= 0 || errno != ENOENT)
344 {
345 ereport(ERROR,
346 (errcode(ERRCODE_DUPLICATE_FILE),
347 errmsg("cannot rename to target file \"%s\"",
348 fn3 ? fn3 : fn2)));
349 }
350
351 if (fn3)
352 {
353 if (rename(fn2, fn3) != 0)
354 {
355 ereport(ERROR,
356 (errcode_for_file_access(),
357 errmsg("could not rename \"%s\" to \"%s\": %m",
358 fn2, fn3)));
359 }
360 if (rename(fn1, fn2) != 0)
361 {
362 ereport(WARNING,
363 (errcode_for_file_access(),
364 errmsg("could not rename \"%s\" to \"%s\": %m",
365 fn1, fn2)));

Callers 2

pg_file_renameFunction · 0.70
pg_file_rename_v1_1Function · 0.70

Calls 4

errcode_for_file_accessFunction · 0.50
errmsgFunction · 0.50
errcodeFunction · 0.50

Tested by

no test coverage detected