5 #include "filedata.hpp"
9 vector<string> split( const string &line, char c, int limit = -1 ) {
10 string::size_type start = 0, end = 0;
13 while( 0 != limit-- && end != line.size() ) {
17 end = line.find( c, start );
18 if( end == string::npos ) {
22 out.push_back( line.substr( start, end-start ) );
28 ostream &operator<<( ostream &o, const FileData *d) {
29 return operator<<( o, *d );
32 ostream &operator<<( ostream &o, const FileData &d ) {
33 o << d.getFileType() << ' ';
34 o << d.getPermissions() << ' ';
35 o << d.getUserName() << ' ';
36 o << d.getGroupName() << ' ';
37 o << d.getFileSize() << ' ';
38 o << d.getModifiedDate() << ' ';
39 o << d.getLastBackupDate() << ' ';
40 o << d.getFileName() << '\0';
45 istream &operator>>( istream &i, FileData *d ) {
46 return operator>>( i, *d );
49 istream &operator>>( istream &i, FileData &d ) {
53 // Todo, don't use char_traits<char> directly here
54 for( c = i.get(); 0 != c && char_traits<char>::eof() != c; c = i.get() ) {
55 file_string.push_back( c );
57 if( char_traits<char>::eof() == c ) {
58 i.setstate( ios_base::eofbit );
61 if( 0 != file_string.size() ) {
63 // type perms user group size datemodified name (8 total)
64 // f 0600 cnb cnb 424 20051015205340 0 ./.git/index
65 vector<string> vals = split( file_string, ' ', 8 );
66 d.setFileType( vals[0][0] );
67 d.setPermissions( vals[1] );
68 d.setUserName( vals[2] );
69 d.setGroupName( vals[3] );
70 d.setFileSize( atoll( vals[4].c_str() ) );
71 d.setModifiedDate( atoll( vals[5].c_str() ) );
72 d.setLastBackupDate( atoll( vals[6].c_str() ) );
73 d.setFileName( vals[7] );
79 bool needs_backup( const FileData *before, const FileData *after ) {
80 assert( before->getFileName() == after->getFileName() );
82 if( after->getLastBackupDate() < after->getModifiedDate() ) return true;
84 if( before->getFileType() != after->getFileType() ) return true;
85 if( before->getPermissions() != after->getPermissions() ) return true;
86 if( before->getUserName() != after->getUserName() ) return true;
87 if( before->getGroupName() != after->getGroupName() ) return true;
88 if( before->getFileSize() != after->getFileSize() ) return true;