Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit756060e

Browse files
committed
fio_symlink() refactor
1 parent7e2785b commit756060e

File tree

2 files changed

+27
-13
lines changed

2 files changed

+27
-13
lines changed

‎src/catchup.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -862,7 +862,7 @@ do_catchup(const char *source_pgdata, const char *dest_pgdata, int num_threads,
862862
/* create link to linked_path */
863863
if (fio_symlink(FIO_LOCAL_HOST,linked_path,to_path, true)<0)
864864
elog(ERROR,"Could not create symbolic link \"%s\" -> \"%s\": %s",
865-
linked_path,to_path,strerror(errno));
865+
to_path,linked_path,strerror(errno));
866866
}
867867
}
868868

‎src/utils/file.c‎

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1256,18 +1256,27 @@ fio_symlink(fio_location location, const char* target, const char* link_path, bo
12561256
{
12571257
if (fio_is_remote(location))
12581258
{
1259-
fio_headerhdr;
12601259
size_ttarget_len=strlen(target)+1;
12611260
size_tlink_path_len=strlen(link_path)+1;
1262-
hdr.cop=FIO_SYMLINK;
1263-
hdr.handle=-1;
1264-
hdr.size=target_len+link_path_len;
1265-
hdr.arg=overwrite ?1 :0;
1261+
fio_headerhdr= {
1262+
.cop=FIO_SYMLINK,
1263+
.handle=-1,
1264+
.size=target_len+link_path_len,
1265+
.arg=overwrite ?1 :0,
1266+
};
12661267

12671268
IO_CHECK(fio_write_all(fio_stdout,&hdr,sizeof(hdr)),sizeof(hdr));
12681269
IO_CHECK(fio_write_all(fio_stdout,target,target_len),target_len);
12691270
IO_CHECK(fio_write_all(fio_stdout,link_path,link_path_len),link_path_len);
12701271

1272+
IO_CHECK(fio_read_all(fio_stdin,&hdr,sizeof(hdr)),sizeof(hdr));
1273+
Assert(hdr.cop==FIO_SYMLINK);
1274+
1275+
if (hdr.arg!=0)
1276+
{
1277+
errno=hdr.arg;
1278+
return-1;
1279+
}
12711280
return0;
12721281
}
12731282
else
@@ -1280,17 +1289,22 @@ fio_symlink(fio_location location, const char* target, const char* link_path, bo
12801289
}
12811290

12821291
staticvoid
1283-
fio_symlink_impl(intout,char*buf,booloverwrite)
1292+
fio_symlink_impl(constchar*target,constchar*link_path,booloverwrite,intout)
12841293
{
1285-
char*linked_path=buf;
1286-
char*link_path=buf+strlen(buf)+1;
1294+
fio_headerhdr= {
1295+
.cop=FIO_SYMLINK,
1296+
.handle=-1,
1297+
.size=0,
1298+
.arg=0,
1299+
};
12871300

12881301
if (overwrite)
12891302
remove_file_or_dir(link_path);
12901303

1291-
if (symlink(linked_path,link_path))
1292-
elog(ERROR,"Could not create symbolic link \"%s\": %s",
1293-
link_path,strerror(errno));
1304+
if (symlink(target,link_path)!=0)
1305+
hdr.arg=errno;
1306+
1307+
IO_CHECK(fio_write_all(out,&hdr,sizeof(hdr)),sizeof(hdr));
12941308
}
12951309

12961310
/* Rename file */
@@ -3428,7 +3442,7 @@ fio_communicate(int in, int out)
34283442
fio_rename_impl(buf,buf+strlen(buf)+1,out);
34293443
break;
34303444
caseFIO_SYMLINK:/* Create symbolic link */
3431-
fio_symlink_impl(out,buf,hdr.arg>0 ? true : false);
3445+
fio_symlink_impl(buf,buf+strlen(buf)+1,hdr.arg==1,out);
34323446
break;
34333447
caseFIO_REMOVE:/* Remove file or directory (TODO: Win32) */
34343448
fio_remove_impl(buf,hdr.arg==1,out);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp