5 #include "filedata.hpp"
9 FileData::FileData( char _type,
13 unsigned long long _size,
14 unsigned long long _modified_date,
15 unsigned long long _last_backup,
18 permissions( _permissions ),
22 modified_date( _modified_date ),
23 last_backup_date( _last_backup ),
27 vector<string> split( const string &line, char c, int limit = -1 ) {
28 string::size_type start = 0, end = 0;
31 while( 0 != limit-- && end != line.size() ) {
35 end = line.find( c, start );
36 if( end == string::npos ) {
40 out.push_back( line.substr( start, end-start ) );
46 ostream &operator<<( const FileData &d, ostream &o ) {
47 o << d.getFileType() << ' ';
48 o << d.getPermissions() << ' ';
49 o << d.getUserName() << ' ';
50 o << d.getGroupName() << ' ';
51 o << d.getFileSize() << ' ';
52 o << d.getModifiedDate() << ' ';
53 o << d.getLastBackupDate() << ' ';
54 o << d.getFileName() << '\0';
59 istream &operator>>( istream &i, FileData &d ) {
62 for( int c = i.get(); 0 != c && ! i.eof(); c = i.get() ) {
63 file_string.push_back( c );
66 if( 0 != file_string.size() ) {
68 // type perms user group size datemodified name (8 total)
69 // f 0600 cnb cnb 424 20051015205340 0 ./.git/index
70 vector<string> vals = split( file_string, ' ', 8 );
71 d.setFileType( vals[0][0] );
72 d.setPermissions( vals[1] );
73 d.setUserName( vals[2] );
74 d.setGroupName( vals[3] );
75 d.setFileSize( atoi( vals[4].c_str() ) );
76 d.setModifiedDate( atoi( vals[5].c_str() ) );
77 d.setLastBackupDate( atoi( vals[6].c_str() ) );
78 d.setFileName( vals[7] );