@@ -1751,15 +1751,46 @@ static int dsync_strmap_compare(
17511751 continue ;
17521752 }
17531753
1754- /* for now, we can only compare content of regular files */
1755- /* TODO: add support for symlinks */
1756- if (! S_ISREG (dst_mode )) {
1757- /* not regular file, take them as common content */
1754+ /* for now, we can only compare content of regular files and symlinks */
1755+ if (! S_ISREG (dst_mode ) && ! S_ISLNK (dst_mode )) {
1756+ /* not regular file or symlink, take them as common content */
17581757 dsync_strmap_item_update (src_map , key , DCMPF_CONTENT , DCMPS_COMMON );
17591758 dsync_strmap_item_update (dst_map , key , DCMPF_CONTENT , DCMPS_COMMON );
17601759 continue ;
17611760 }
17621761
1762+ /* if symlink, check if targets of source and destination files match. If not,
1763+ * mark the files as being different. */
1764+ if (S_ISLNK (dst_mode )) {
1765+ const char * src_name = mfu_flist_file_get_name (src_list , src_index );
1766+ const char * dst_name = mfu_flist_file_get_name (dst_list , dst_index );
1767+ int compare_rc = mfu_compare_symlinks (src_name , dst_name , mfu_src_file , mfu_dst_file );
1768+ if (compare_rc == -1 ) {
1769+ /* we hit an error while reading the symlink */
1770+ rc = -1 ;
1771+ MFU_LOG (MFU_LOG_ERR ,
1772+ "Failed to readlink on %s and/or %s. Assuming contents are different." ,
1773+ src_name , dst_name );
1774+ }
1775+ if (!compare_rc ) {
1776+ /* update to say contents of the files were found to be the same */
1777+ dsync_strmap_item_update (src_map , key , DCMPF_CONTENT , DCMPS_COMMON );
1778+ dsync_strmap_item_update (dst_map , key , DCMPF_CONTENT , DCMPS_COMMON );
1779+ } else {
1780+ /* update to say contents of the symlinks were found to be different */
1781+ dsync_strmap_item_update (src_map , key , DCMPF_CONTENT , DCMPS_DIFFER );
1782+ dsync_strmap_item_update (dst_map , key , DCMPF_CONTENT , DCMPS_DIFFER );
1783+
1784+ /* if the destinations are different then we need to remove the file in
1785+ * the dst directory, and replace it with the one in the src directory */
1786+ if (compare_rc > 0 && !options .dry_run ) {
1787+ mfu_flist_file_copy (src_list , src_index , src_cp_list );
1788+ mfu_flist_file_copy (dst_list , dst_index , dst_remove_list );
1789+ }
1790+ }
1791+ continue ;
1792+ }
1793+
17631794 /* first check whether file sizes match */
17641795 dsync_state state ;
17651796 tmp_rc = dsync_strmap_item_state (src_map , key , DCMPF_SIZE , & state );
0 commit comments