@@ -1176,18 +1176,27 @@ fio_symlink(fio_location location, const char* target, const char* link_path, bo
11761176{
11771177 if (fio_is_remote (location ))
11781178 {
1179- fio_header hdr ;
11801179 size_t target_len = strlen (target ) + 1 ;
11811180 size_t link_path_len = strlen (link_path ) + 1 ;
1182- hdr .cop = FIO_SYMLINK ;
1183- hdr .handle = -1 ;
1184- hdr .size = target_len + link_path_len ;
1185- hdr .arg = overwrite ? 1 : 0 ;
1181+ fio_header hdr = {
1182+ .cop = FIO_SYMLINK ,
1183+ .handle = -1 ,
1184+ .size = target_len + link_path_len ,
1185+ .arg = overwrite ? 1 : 0 ,
1186+ };
11861187
11871188 IO_CHECK (fio_write_all (fio_stdout , & hdr , sizeof (hdr )), sizeof (hdr ));
11881189 IO_CHECK (fio_write_all (fio_stdout , target , target_len ), target_len );
11891190 IO_CHECK (fio_write_all (fio_stdout , link_path , link_path_len ), link_path_len );
11901191
1192+ IO_CHECK (fio_read_all (fio_stdin , & hdr , sizeof (hdr )), sizeof (hdr ));
1193+ Assert (hdr .cop == FIO_SYMLINK );
1194+
1195+ if (hdr .arg != 0 )
1196+ {
1197+ errno = hdr .arg ;
1198+ return -1 ;
1199+ }
11911200 return 0 ;
11921201 }
11931202 else
@@ -1200,17 +1209,22 @@ fio_symlink(fio_location location, const char* target, const char* link_path, bo
12001209}
12011210
12021211static void
1203- fio_symlink_impl (int out , char * buf , bool overwrite )
1212+ fio_symlink_impl (const char * target , const char * link_path , bool overwrite , int out )
12041213{
1205- char * linked_path = buf ;
1206- char * link_path = buf + strlen (buf ) + 1 ;
1214+ fio_header hdr = {
1215+ .cop = FIO_SYMLINK ,
1216+ .handle = -1 ,
1217+ .size = 0 ,
1218+ .arg = 0 ,
1219+ };
12071220
12081221 if (overwrite )
12091222 remove (link_path );
12101223
1211- if (symlink (linked_path , link_path ))
1212- elog (ERROR , "Could not create symbolic link \"%s\": %s" ,
1213- link_path , strerror (errno ));
1224+ if (symlink (target , link_path ) != 0 )
1225+ hdr .arg = errno ;
1226+
1227+ IO_CHECK (fio_write_all (out , & hdr , sizeof (hdr )), sizeof (hdr ));
12141228}
12151229
12161230/* Rename file */
@@ -3879,7 +3893,7 @@ fio_communicate(int in, int out)
38793893 fio_rename_impl (buf , buf + strlen (buf ) + 1 , out );
38803894 break ;
38813895 case FIO_SYMLINK : /* Create symbolic link */
3882- fio_symlink_impl (out , buf , hdr .arg > 0 ? true : false );
3896+ fio_symlink_impl (buf , buf + strlen ( buf ) + 1 , hdr .arg == 1 , out );
38833897 break ;
38843898 case FIO_REMOVE : /* Remove file or directory */
38853899 fio_remove_impl (buf , hdr .arg == 1 , out );
0 commit comments