Changeset 160


Ignore:
Timestamp:
Feb 4, 2010, 4:28:02 PM (11 years ago)
Author:
ogrimm
Message:
Data written into one directory per month
File:
1 edited

Legend:

Unmodified
Added
Removed
  • Evidence/DColl.cc

    r159 r160  
    277277        time_t Time = time(NULL);
    278278        struct tm *T = localtime(&Time);
    279         ostringstream Buf;
    280        
    281         // Generate file name from date
     279       
     280        // Get time structure with date rollover
    282281        if(T->tm_hour >= DATE_ROLLOVER) T->tm_mday++;
    283282        if (mktime(T) == -1) State(ERROR, "mktime() failed, check filename");
    284         Buf << DataDir << "/" << T->tm_year+1900 << setw(2) << setfill('0') << T->tm_mon+1 << T->tm_mday << ".slow";
    285        
    286         // Copy filename to permanent buffer
    287         delete[] Filename;
    288         Filename = new char [Buf.str().size()+1];
    289         strcpy(Filename, Buf.str().c_str());
     283
     284        // Create direcory if not existing (ignore error if already existing)
     285        char *Dir;
     286        if (asprintf(&Dir, "%s/%d%02d",DataDir, T->tm_year+1900, T->tm_mon + 1) == -1) {
     287          State(FATAL, "asprintf() failed, could not create direcory name");   
     288        }
     289        if(mkdir(Dir, S_IRWXU|S_IRWXG)==-1 && errno!=EEXIST) {
     290          State(FATAL, "Could not create direcory '%s' (%s)", Dir, strerror(errno));
     291        }
     292
     293        // Create filename
     294        free(Filename);
     295        if (asprintf(&Filename, "%s/%d%02d%02d.slow", Dir, T->tm_year+1900, T->tm_mon+1, T->tm_mday) == 1) {
     296          State(FATAL, "asprintf() failed, could not create filename");           
     297        }
     298        free(Dir);
    290299       
    291300        // Open file
Note: See TracChangeset for help on using the changeset viewer.