chooses hash type, giving priority to types both sides have in common
(ci *fs.ConfigInfo)
| 138 | |
| 139 | // chooses hash type, giving priority to types both sides have in common |
| 140 | func (b *bisyncRun) setHashType(ci *fs.ConfigInfo) { |
| 141 | b.downloadHashOpt.downloadHash = b.opt.Compare.DownloadHash |
| 142 | if b.opt.Compare.NoSlowHash && b.opt.Compare.SlowHashDetected { |
| 143 | fs.Infof(nil, "Not checking for common hash as at least one slow hash detected.") |
| 144 | } else { |
| 145 | common := b.fs1.Hashes().Overlap(b.fs2.Hashes()) |
| 146 | if common.Count() > 0 && common.GetOne() != hash.None { |
| 147 | ht := common.GetOne() |
| 148 | b.opt.Compare.HashType1 = ht |
| 149 | b.opt.Compare.HashType2 = ht |
| 150 | if !b.opt.Compare.SlowHashSyncOnly || !b.opt.Compare.SlowHashDetected { |
| 151 | return |
| 152 | } |
| 153 | } else if b.opt.Compare.SlowHashSyncOnly && b.opt.Compare.SlowHashDetected { |
| 154 | fs.Log(b.fs2, Color(terminal.YellowFg, "Ignoring --slow-hash-sync-only and falling back to --no-slow-hash as Path1 and Path2 have no hashes in common.")) |
| 155 | b.opt.Compare.SlowHashSyncOnly = false |
| 156 | b.opt.Compare.NoSlowHash = true |
| 157 | ci.CheckSum = false |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | if !b.opt.Compare.DownloadHash && !b.opt.Compare.SlowHashSyncOnly { |
| 162 | fs.Log(b.fs2, Color(terminal.YellowFg, "--checksum is in use but Path1 and Path2 have no hashes in common; falling back to --compare modtime,size for sync. (Use --compare size or --size-only to ignore modtime)")) |
| 163 | fs.Infof("Path1 hashes", "%v", b.fs1.Hashes().String()) |
| 164 | fs.Infof("Path2 hashes", "%v", b.fs2.Hashes().String()) |
| 165 | b.opt.Compare.Modtime = true |
| 166 | b.opt.Compare.Size = true |
| 167 | ci.CheckSum = false |
| 168 | } |
| 169 | if (b.opt.Compare.NoSlowHash || b.opt.Compare.SlowHashSyncOnly) && b.fs1.Features().SlowHash { |
| 170 | fs.Infoc(nil, Color(terminal.YellowFg, "Slow hash detected on Path1. Will ignore checksum due to slow-hash settings")) |
| 171 | b.opt.Compare.HashType1 = hash.None |
| 172 | } else { |
| 173 | b.opt.Compare.HashType1 = b.fs1.Hashes().GetOne() |
| 174 | if b.opt.Compare.HashType1 != hash.None { |
| 175 | fs.Logf(b.fs1, Color(terminal.YellowFg, "will use %s for same-side diffs on Path1 only"), b.opt.Compare.HashType1) |
| 176 | } |
| 177 | } |
| 178 | if (b.opt.Compare.NoSlowHash || b.opt.Compare.SlowHashSyncOnly) && b.fs2.Features().SlowHash { |
| 179 | fs.Infoc(nil, Color(terminal.YellowFg, "Slow hash detected on Path2. Will ignore checksum due to slow-hash settings")) |
| 180 | b.opt.Compare.HashType2 = hash.None |
| 181 | } else { |
| 182 | b.opt.Compare.HashType2 = b.fs2.Hashes().GetOne() |
| 183 | if b.opt.Compare.HashType2 != hash.None { |
| 184 | fs.Logf(b.fs2, Color(terminal.YellowFg, "will use %s for same-side diffs on Path2 only"), b.opt.Compare.HashType2) |
| 185 | } |
| 186 | } |
| 187 | if b.opt.Compare.HashType1 == hash.None && b.opt.Compare.HashType2 == hash.None && !b.opt.Compare.DownloadHash { |
| 188 | fs.Log(nil, Color(terminal.YellowFg, "WARNING: Ignoring checksums globally as hashes are ignored or unavailable on both sides.")) |
| 189 | b.opt.Compare.Checksum = false |
| 190 | ci.CheckSum = false |
| 191 | b.opt.IgnoreListingChecksum = true |
| 192 | } |
| 193 | } |
| 194 | |
| 195 | // returns true if the times are definitely different (by more than the modify window). |
| 196 | // returns false if equal, within modify window, or if either is unknown. |