@@ -1256,18 +1256,27 @@ fio_symlink(fio_location location, const char* target, const char* link_path, bo
1256
1256
{
1257
1257
if (fio_is_remote (location ))
1258
1258
{
1259
- fio_header hdr ;
1260
1259
size_t target_len = strlen (target ) + 1 ;
1261
1260
size_t link_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_header hdr = {
1262
+ .cop = FIO_SYMLINK ,
1263
+ .handle = -1 ,
1264
+ .size = target_len + link_path_len ,
1265
+ .arg = overwrite ? 1 : 0 ,
1266
+ };
1266
1267
1267
1268
IO_CHECK (fio_write_all (fio_stdout , & hdr , sizeof (hdr )), sizeof (hdr ));
1268
1269
IO_CHECK (fio_write_all (fio_stdout , target , target_len ), target_len );
1269
1270
IO_CHECK (fio_write_all (fio_stdout , link_path , link_path_len ), link_path_len );
1270
1271
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
+ }
1271
1280
return 0 ;
1272
1281
}
1273
1282
else
@@ -1280,17 +1289,22 @@ fio_symlink(fio_location location, const char* target, const char* link_path, bo
1280
1289
}
1281
1290
1282
1291
static void
1283
- fio_symlink_impl (int out , char * buf , bool overwrite )
1292
+ fio_symlink_impl (const char * target , const char * link_path , bool overwrite , int out )
1284
1293
{
1285
- char * linked_path = buf ;
1286
- char * link_path = buf + strlen (buf ) + 1 ;
1294
+ fio_header hdr = {
1295
+ .cop = FIO_SYMLINK ,
1296
+ .handle = -1 ,
1297
+ .size = 0 ,
1298
+ .arg = 0 ,
1299
+ };
1287
1300
1288
1301
if (overwrite )
1289
1302
remove_file_or_dir (link_path );
1290
1303
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 ));
1294
1308
}
1295
1309
1296
1310
/* Rename file */
@@ -3428,7 +3442,7 @@ fio_communicate(int in, int out)
3428
3442
fio_rename_impl (buf , buf + strlen (buf ) + 1 , out );
3429
3443
break ;
3430
3444
case FIO_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 );
3432
3446
break ;
3433
3447
case FIO_REMOVE : /* Remove file or directory (TODO: Win32) */
3434
3448
fio_remove_impl (buf , hdr .arg == 1 , out );
0 commit comments