- Timestamp:
- 08/03/2010 22:00:55 (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
box/RELEASE/0.11rc7/lib/backupclient/BackupClientFileAttributes.cpp
r2493 r2663 79 79 { 80 80 int32_t uid, gid, mode; 81 #ifdef WIN32 82 int64_t fileCreationTime; 83 #endif 81 84 } attributeHashData; 82 85 … … 222 225 // Function 223 226 // Name: BackupClientFileAttributes::Compare(const BackupClientFileAttributes &, bool) 224 // Purpose: Compare, optionally ignoring the attribute modification time and/or modification time, and some data which is 225 // irrelevant in practise (eg file generation number) 227 // Purpose: Compare, optionally ignoring the attribute 228 // modification time and/or modification time, and some 229 // data which is irrelevant in practise (eg file 230 // generation number) 226 231 // Created: 10/12/03 227 232 // 228 233 // -------------------------------------------------------------------------- 229 bool BackupClientFileAttributes::Compare(const BackupClientFileAttributes &rAttr, bool IgnoreAttrModTime, bool IgnoreModTime) const 234 bool BackupClientFileAttributes::Compare(const BackupClientFileAttributes &rAttr, 235 bool IgnoreAttrModTime, bool IgnoreModTime) const 230 236 { 231 237 EnsureClearAvailable(); … … 235 241 if(mpClearAttributes->GetSize() != rAttr.mpClearAttributes->GetSize()) 236 242 { 243 BOX_TRACE("Attribute Compare: Attributes objects are " 244 "different sizes, cannot compare them: local " << 245 mpClearAttributes->GetSize() << " bytes, remote " << 246 rAttr.mpClearAttributes->GetSize() << " bytes"); 237 247 return false; 238 248 } … … 242 252 attr_StreamFormat *a1 = (attr_StreamFormat*)mpClearAttributes->GetBuffer(); 243 253 attr_StreamFormat *a2 = (attr_StreamFormat*)rAttr.mpClearAttributes->GetBuffer(); 244 245 if(a1->AttributeType != a2->AttributeType 246 || a1->UID != a2->UID 247 || a1->GID != a2->GID 248 || a1->UserDefinedFlags != a2->UserDefinedFlags 249 || a1->Mode != a2->Mode) 250 { 251 return false; 252 } 253 254 255 #define COMPARE(attribute, message) \ 256 if (a1->attribute != a2->attribute) \ 257 { \ 258 BOX_TRACE("Attribute Compare: " << message << " differ: " \ 259 "local " << ntoh(a1->attribute) << ", " \ 260 "remote " << ntoh(a2->attribute)); \ 261 return false; \ 262 } 263 COMPARE(AttributeType, "Attribute types"); 264 COMPARE(UID, "UIDs"); 265 COMPARE(GID, "GIDs"); 266 COMPARE(UserDefinedFlags, "User-defined flags"); 267 COMPARE(Mode, "Modes"); 268 254 269 if(!IgnoreModTime) 255 270 { 256 int t1 = a1->ModificationTime / 1000000; 257 int t2 = a2->ModificationTime / 1000000; 258 if(t1 != t2) 259 { 271 uint64_t t1 = box_ntoh64(a1->ModificationTime); 272 uint64_t t2 = box_ntoh64(a2->ModificationTime); 273 time_t s1 = BoxTimeToSeconds(t1); 274 time_t s2 = BoxTimeToSeconds(t2); 275 if(s1 != s2) 276 { 277 BOX_TRACE("Attribute Compare: File modification " 278 "times differ: local " << 279 FormatTime(t1, true) << " (" << s1 << "), " 280 "remote " << 281 FormatTime(t2, true) << " (" << s2 << ")"); 260 282 return false; 261 283 } 262 284 } 263 285 264 286 if(!IgnoreAttrModTime) 265 287 { 266 int t1 = a1->AttrModificationTime / 1000000; 267 int t2 = a2->AttrModificationTime / 1000000; 268 if(t1 != t2) 269 { 288 uint64_t t1 = box_ntoh64(a1->AttrModificationTime); 289 uint64_t t2 = box_ntoh64(a2->AttrModificationTime); 290 time_t s1 = BoxTimeToSeconds(t1); 291 time_t s2 = BoxTimeToSeconds(t2); 292 if(s1 != s2) 293 { 294 BOX_TRACE("Attribute Compare: Attribute modification " 295 "times differ: local " << 296 FormatTime(t1, true) << " (" << s1 << "), " 297 "remote " << 298 FormatTime(t2, true) << " (" << s2 << ")"); 270 299 return false; 271 300 } … … 277 306 { 278 307 // Symlink strings don't match. This also compares xattrs 279 if(::memcmp(a1 + 1, a2 + 1, size - sizeof(attr_StreamFormat)) != 0) 280 { 308 int datalen = size - sizeof(attr_StreamFormat); 309 310 if(::memcmp(a1 + 1, a2 + 1, datalen) != 0) 311 { 312 std::string s1((char *)(a1 + 1), datalen); 313 std::string s2((char *)(a2 + 1), datalen); 314 BOX_TRACE("Attribute Compare: Symbolic link target " 315 "or extended attributes differ: " 316 "local " << PrintEscapedBinaryData(s1) << ", " 317 "remote " << PrintEscapedBinaryData(s2)); 281 318 return false; 282 319 } … … 604 641 } 605 642 643 // -------------------------------------------------------------------------- 644 // 645 // Function 646 // Name: BackupClientFileAttributes::GetModificationTimes() 647 // Purpose: Returns the modification time embedded in the 648 // attributes. 649 // Created: 2010/02/24 650 // 651 // -------------------------------------------------------------------------- 652 void BackupClientFileAttributes::GetModificationTimes( 653 box_time_t *pModificationTime, 654 box_time_t *pAttrModificationTime) const 655 { 656 // Got something loaded 657 if(GetSize() <= 0) 658 { 659 THROW_EXCEPTION(BackupStoreException, AttributesNotLoaded); 660 } 661 662 // Make sure there are clear attributes to use 663 EnsureClearAvailable(); 664 ASSERT(mpClearAttributes != 0); 665 666 // Check if the decrypted attributes are small enough, and the type of attributes stored 667 if(mpClearAttributes->GetSize() < (int)sizeof(int32_t)) 668 { 669 THROW_EXCEPTION(BackupStoreException, AttributesNotUnderstood); 670 } 671 int32_t *type = (int32_t*)mpClearAttributes->GetBuffer(); 672 ASSERT(type != 0); 673 if(ntohl(*type) != ATTRIBUTETYPE_GENERIC_UNIX) 674 { 675 // Don't know what to do with these 676 THROW_EXCEPTION(BackupStoreException, AttributesNotUnderstood); 677 } 678 679 // Check there is enough space for an attributes block 680 if(mpClearAttributes->GetSize() < (int)sizeof(attr_StreamFormat)) 681 { 682 // Too small 683 THROW_EXCEPTION(BackupStoreException, AttributesNotLoaded); 684 } 685 686 // Get pointer to structure 687 attr_StreamFormat *pattr = (attr_StreamFormat*)mpClearAttributes->GetBuffer(); 688 689 if(pModificationTime) 690 { 691 *pModificationTime = box_ntoh64(pattr->ModificationTime); 692 } 693 694 if(pAttrModificationTime) 695 { 696 *pAttrModificationTime = box_ntoh64(pattr->AttrModificationTime); 697 } 698 } 606 699 607 700 // -------------------------------------------------------------------------- … … 1033 1126 // 1034 1127 // Function 1035 // Name: BackupClientFileAttributes::GenerateAttributeHash(struct stat &, const std::string &, const std::string &) 1036 // Purpose: Generate a 64 bit hash from the attributes, used to detect changes. 1037 // Include filename in the hash, so that it changes from one file to another, 1038 // so don't reveal identical attributes. 1128 // Name: BackupClientFileAttributes::GenerateAttributeHash( 1129 // struct stat &, const std::string &, 1130 // const std::string &) 1131 // Purpose: Generate a 64 bit hash from the attributes, used to 1132 // detect changes. Include filename in the hash, so 1133 // that it changes from one file to another, so don't 1134 // reveal identical attributes. 1039 1135 // Created: 25/4/04 1040 1136 // 1041 1137 // -------------------------------------------------------------------------- 1042 uint64_t BackupClientFileAttributes::GenerateAttributeHash(EMU_STRUCT_STAT &st, const std::string &filename, const std::string &leafname) 1138 uint64_t BackupClientFileAttributes::GenerateAttributeHash(EMU_STRUCT_STAT &st, 1139 const std::string &filename, const std::string &leafname) 1043 1140 { 1044 1141 if(sAttributeHashSecretLength == 0) … … 1055 1152 hashData.mode = htonl(st.st_mode); 1056 1153 1154 #ifdef WIN32 1155 // On Windows, the "file attribute modification time" is the 1156 // file creation time, and we want to back this up, restore 1157 // it and compare it. 1158 // 1159 // On other platforms, it's not very important and can't 1160 // reliably be set to anything other than the current time. 1161 hashData.fileCreationTime = box_hton64(st.st_ctime); 1162 #endif 1163 1057 1164 StreamableMemBlock xattr; 1058 1165 FillExtendedAttr(xattr, filename.c_str()); … … 1063 1170 digest.Add(xattr.GetBuffer(), xattr.GetSize()); 1064 1171 digest.Add(leafname.c_str(), leafname.size()); 1065 digest.Add(sAttributeHashSecret, sAttributeHashSecretLength); 1172 digest.Add(sAttributeHashSecret, sAttributeHashSecretLength); 1066 1173 digest.Finish(); 1067 1174
Note: See TracChangeset
for help on using the changeset viewer.
