@@ -882,7 +882,7 @@ static int dsync_strmap_compare_data(
882
882
/* get chunk size for copying files (just hard-coded for now) */
883
883
uint64_t chunk_size = copy_opts -> chunk_size ;
884
884
885
- /* get the linked list of file chunks for the src and dest */
885
+ /* get the linked list of regular file chunks for the src and dest */
886
886
mfu_file_chunk * src_head = mfu_file_chunk_list_alloc (src_compare_list , chunk_size );
887
887
mfu_file_chunk * dst_head = mfu_file_chunk_list_alloc (dst_compare_list , chunk_size );
888
888
@@ -963,8 +963,18 @@ static int dsync_strmap_compare_data(
963
963
/* ignore prefix portion of path to use as key */
964
964
name += strlen_prefix ;
965
965
966
- /* get comparison results for this item */
967
- int flag = results [i ];
966
+ mfu_filetype type = mfu_flist_file_get_type (src_compare_list , i );
967
+ int flag = 0 ;
968
+ if (type == MFU_TYPE_LINK ) {
969
+ /* symlinks have not been compared above, their targets are compared now */
970
+ flag = mfu_compare_symlinks (mfu_flist_file_get_name (src_compare_list , i ),
971
+ mfu_flist_file_get_name (dst_compare_list , i ),
972
+ mfu_src_file , mfu_dst_file );
973
+ } else {
974
+ /* get comparison results for this regular file */
975
+ flag = results [i ];
976
+ }
977
+
968
978
969
979
/* set flag in strmap to record status of file */
970
980
if (flag != 0 ) {
@@ -973,7 +983,7 @@ static int dsync_strmap_compare_data(
973
983
dsync_strmap_item_update (dst_map , name , DCMPF_CONTENT , DCMPS_DIFFER );
974
984
975
985
/* mark file to be deleted from destination, copied from source */
976
- if (use_hardlinks ) {
986
+ if (use_hardlinks || type == MFU_TYPE_LINK ) {
977
987
mfu_flist_file_copy (dst_compare_list , i , dst_remove_list );
978
988
mfu_flist_file_copy (src_compare_list , i , src_cp_list );
979
989
}
@@ -1171,7 +1181,9 @@ static int dsync_strmap_compare_lite(
1171
1181
mfu_flist dst_remove_list ,
1172
1182
strmap * dst_map ,
1173
1183
size_t strlen_prefix ,
1174
- bool use_hardlinks )
1184
+ bool use_hardlinks ,
1185
+ mfu_file_t * mfu_src_file ,
1186
+ mfu_file_t * mfu_dst_file )
1175
1187
{
1176
1188
/* assume we'll succeed */
1177
1189
int rc = 0 ;
@@ -1184,6 +1196,7 @@ static int dsync_strmap_compare_lite(
1184
1196
for (idx = 0 ; idx < size ; idx ++ ) {
1185
1197
/* lookup name of file based on id to send to strmap updata call */
1186
1198
const char * name = mfu_flist_file_get_name (src_compare_list , idx );
1199
+ const mfu_filetype type = mfu_flist_file_get_type (src_compare_list , idx );
1187
1200
1188
1201
/* ignore prefix portion of path to use as key */
1189
1202
name += strlen_prefix ;
@@ -1211,6 +1224,20 @@ static int dsync_strmap_compare_lite(
1211
1224
mfu_flist_file_copy (dst_compare_list , idx , dst_remove_list );
1212
1225
mfu_flist_file_copy (src_compare_list , idx , src_cp_list );
1213
1226
}
1227
+ /* if symlink, check if targets of source and destination files match. If not, mark the
1228
+ * files as being different. */
1229
+ } else if (type == MFU_TYPE_LINK ) {
1230
+ if (mfu_compare_symlinks (mfu_flist_file_get_name (src_compare_list , idx ),
1231
+ mfu_flist_file_get_name (dst_compare_list , idx ),
1232
+ mfu_src_file , mfu_dst_file ) == 0 ) {
1233
+ /* update to say contents of the files were found to be the same */
1234
+ dsync_strmap_item_update (src_map , name , DCMPF_CONTENT , DCMPS_COMMON );
1235
+ dsync_strmap_item_update (dst_map , name , DCMPF_CONTENT , DCMPS_COMMON );
1236
+ } else {
1237
+ /* update to say contents of the symlinks were found to be different */
1238
+ dsync_strmap_item_update (src_map , name , DCMPF_CONTENT , DCMPS_DIFFER );
1239
+ dsync_strmap_item_update (dst_map , name , DCMPF_CONTENT , DCMPS_DIFFER );
1240
+ }
1214
1241
} else {
1215
1242
/* update to say contents of the files were found to be the same */
1216
1243
dsync_strmap_item_update (src_map , name , DCMPF_CONTENT , DCMPS_COMMON );
@@ -1748,10 +1775,9 @@ static int dsync_strmap_compare(
1748
1775
continue ;
1749
1776
}
1750
1777
1751
- /* for now, we can only compare content of regular files */
1752
- /* TODO: add support for symlinks */
1753
- if (! S_ISREG (dst_mode )) {
1754
- /* not regular file, take them as common content */
1778
+ /* for now, we can only compare content of regular files and symlinks */
1779
+ if (! S_ISREG (dst_mode ) && !S_ISLNK (dst_mode )) {
1780
+ /* not regular file or symlink, take them as common content */
1755
1781
dsync_strmap_item_update (src_map , key , DCMPF_CONTENT , DCMPS_COMMON );
1756
1782
dsync_strmap_item_update (dst_map , key , DCMPF_CONTENT , DCMPS_COMMON );
1757
1783
continue ;
@@ -1832,7 +1858,7 @@ static int dsync_strmap_compare(
1832
1858
* adds files to remove and copy lists if different */
1833
1859
tmp_rc = dsync_strmap_compare_lite (src_compare_list , src_cp_list , dst_same_list ,
1834
1860
src_map , dst_compare_list , dst_remove_list , dst_map ,
1835
- strlen_prefix , use_hardlinks
1861
+ strlen_prefix , use_hardlinks , mfu_src_file , mfu_dst_file
1836
1862
);
1837
1863
if (tmp_rc < 0 ) {
1838
1864
rc = -1 ;
0 commit comments