Skip to content

Commit 6ec34f8

Browse files
committed
fix file delete on Windows
1 parent 852c993 commit 6ec34f8

File tree

7 files changed

+44
-39
lines changed

7 files changed

+44
-39
lines changed

src/delete.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -768,7 +768,7 @@ delete_backup_files(pgBackup *backup)
768768
elog(INFO, "Progress: (%zd/%zd). Delete file \"%s\"",
769769
i + 1, num_files, full_path);
770770

771-
pgFileDelete(file, full_path);
771+
pgFileDelete(file->mode, full_path);
772772
}
773773

774774
parray_walk(files, pgFileFree);

src/dir.c

+2-34
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,9 @@ pgFileInit(const char *rel_path)
225225
* If the pgFile points directory, the directory must be empty.
226226
*/
227227
void
228-
pgFileDelete(pgFile *file, const char *full_path)
228+
pgFileDelete(mode_t mode, const char *full_path)
229229
{
230-
if (S_ISDIR(file->mode))
230+
if (S_ISDIR(mode))
231231
{
232232
if (rmdir(full_path) == -1)
233233
{
@@ -252,38 +252,6 @@ pgFileDelete(pgFile *file, const char *full_path)
252252
}
253253
}
254254

255-
/*
256-
* Delete file pointed by the pgFile.
257-
* If the pgFile points directory, the directory must be empty.
258-
*/
259-
void
260-
fio_pgFileDelete(pgFile *file, const char *full_path)
261-
{
262-
if (S_ISDIR(file->mode))
263-
{
264-
if (fio_unlink(full_path, FIO_DB_HOST) == -1)
265-
{
266-
if (errno == ENOENT)
267-
return;
268-
else if (errno == ENOTDIR) /* could be symbolic link */
269-
goto delete_file;
270-
271-
elog(ERROR, "Cannot remove directory \"%s\": %s",
272-
full_path, strerror(errno));
273-
}
274-
return;
275-
}
276-
277-
delete_file:
278-
if (fio_unlink(full_path, FIO_DB_HOST) == -1)
279-
{
280-
if (errno == ENOENT)
281-
return;
282-
elog(ERROR, "Cannot remove file \"%s\": %s", full_path,
283-
strerror(errno));
284-
}
285-
}
286-
287255
/*
288256
* Read the local file to compute its CRC.
289257
* We cannot make decision about file decompression because

src/merge.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,7 @@ merge_chain(parray *parent_chain, pgBackup *full_backup, pgBackup *dest_backup)
806806
/* We need full path, file object has relative path */
807807
join_path_components(full_file_path, full_database_dir, full_file->rel_path);
808808

809-
pgFileDelete(full_file, full_file_path);
809+
pgFileDelete(full_file->mode, full_file_path);
810810
elog(VERBOSE, "Deleted \"%s\"", full_file_path);
811811
}
812812
}
@@ -1141,7 +1141,7 @@ remove_dir_with_files(const char *path)
11411141

11421142
join_path_components(full_path, path, file->rel_path);
11431143

1144-
pgFileDelete(file, full_path);
1144+
pgFileDelete(file->mode, full_path);
11451145
elog(VERBOSE, "Deleted \"%s\"", full_path);
11461146
}
11471147

src/pg_probackup.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -970,7 +970,7 @@ extern pgFile *pgFileNew(const char *path, const char *rel_path,
970970
bool follow_symlink, int external_dir_num,
971971
fio_location location);
972972
extern pgFile *pgFileInit(const char *rel_path);
973-
extern void pgFileDelete(pgFile *file, const char *full_path);
973+
extern void pgFileDelete(mode_t mode, const char *full_path);
974974
extern void fio_pgFileDelete(pgFile *file, const char *full_path);
975975

976976
extern void pgFileFree(void *file);
@@ -1123,6 +1123,7 @@ extern int send_pages(ConnectionArgs* conn_arg, const char *to_fullpath, const c
11231123
BackupMode backup_mode, int ptrack_version_num, const char *ptrack_schema);
11241124

11251125
/* FIO */
1126+
extern void fio_delete(mode_t mode, const char *fullpath, fio_location location);
11261127
extern int fio_send_pages(const char *to_fullpath, const char *from_fullpath, pgFile *file, XLogRecPtr horizonLsn,
11271128
int calg, int clevel, uint32 checksum_version, datapagemap_t *pagemap,
11281129
BlockNumber* err_blknum, char **errormsg, BackupPageHeader2 **headers);

src/restore.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -836,7 +836,7 @@ restore_chain(pgBackup *dest_backup, parray *parent_chain,
836836
join_path_components(fullpath, pgdata_path, file->rel_path);
837837

838838
// fio_pgFileDelete(file, full_file_path);
839-
pgFileDelete(file, fullpath);
839+
fio_delete(file->mode, fullpath, FIO_DB_HOST);
840840
elog(VERBOSE, "Deleted file \"%s\"", fullpath);
841841

842842
/* shrink pgdata list */

src/utils/file.c

+35
Original file line numberDiff line numberDiff line change
@@ -2492,6 +2492,37 @@ static void fio_check_postmaster_impl(int out, char *buf)
24922492
IO_CHECK(fio_write_all(out, &hdr, sizeof(hdr)), sizeof(hdr));
24932493
}
24942494

2495+
/*
2496+
* Delete file pointed by the pgFile.
2497+
* If the pgFile points directory, the directory must be empty.
2498+
*/
2499+
void
2500+
fio_delete(mode_t mode, const char *fullpath, fio_location location)
2501+
{
2502+
if (fio_is_remote(location))
2503+
{
2504+
fio_header hdr;
2505+
2506+
hdr.cop = FIO_DELETE;
2507+
hdr.size = strlen(fullpath) + 1;
2508+
hdr.arg = mode;
2509+
2510+
IO_CHECK(fio_write_all(fio_stdout, &hdr, sizeof(hdr)), sizeof(hdr));
2511+
IO_CHECK(fio_write_all(fio_stdout, fullpath, hdr.size), hdr.size);
2512+
2513+
}
2514+
else
2515+
pgFileDelete(mode, fullpath);
2516+
}
2517+
2518+
static void
2519+
fio_delete_impl(mode_t mode, char *buf)
2520+
{
2521+
char *fullpath = (char*) buf;
2522+
2523+
pgFileDelete(mode, fullpath);
2524+
}
2525+
24952526
/* Execute commands at remote host */
24962527
void fio_communicate(int in, int out)
24972528
{
@@ -2675,6 +2706,10 @@ void fio_communicate(int in, int out)
26752706
/* calculate crc32 for a file */
26762707
fio_check_postmaster_impl(out, buf);
26772708
break;
2709+
case FIO_DELETE:
2710+
/* delete file */
2711+
fio_delete_impl(hdr.arg, buf);
2712+
break;
26782713
case FIO_DISCONNECT:
26792714
hdr.cop = FIO_DISCONNECTED;
26802715
IO_CHECK(fio_write_all(out, &hdr, sizeof(hdr)), sizeof(hdr));

src/utils/file.h

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ typedef enum
2323
FIO_CHMOD,
2424
FIO_SEEK,
2525
FIO_TRUNCATE,
26+
FIO_DELETE,
2627
FIO_PREAD,
2728
FIO_READ,
2829
FIO_LOAD,

0 commit comments

Comments
 (0)