#ifndef cmw_File_hh #define cmw_File_hh #include #include #include #include #include #include #include class SendBufferCompressed; class Counter; #if defined(CMW) #include #endif class File { lil_string name_; mutable bool updated_; mutable file_type fd; mutable uint32_t sz; public: static time_t lastruntime_; File () : fd(0), sz(0) {} explicit File (char const* name) : name_(name), updated_(true), fd(0), sz(0) {} File (File const& orig); template explicit File (ReceiveBufferTCPCompressed& buf) { lil_string(buf).swap(name_); boolReceive(buf, updated_); if (updated_) { #if defined (WIN_DOWS) fd = CreateFile(name_.c_str() , GENERIC_WRITE , FILE_SHARE_READ , NULL , CREATE_ALWAYS , FILE_ATTRIBUTE_NORMAL , 0 ); if (fd == INVALID_HANDLE_VALUE) { throw failure("File::File -- CreateFile failed ") << GetLastError(); } #else fd = open(name_.c_str() , O_WRONLY | O_CREAT | O_TRUNC , S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH ); if (fd < 0) { throw failure("File::File -- open failed. errno is ") << errno; } #endif buf.WriteFile(fd); #ifdef CMW static myMagic mag; mag.checkFile(name_.c_str()); #endif } } ~File (); void Marshal (SendBufferCompressed& buf, bool) const; void CalculateMarshallingSize (Counter& cntr) const; lil_string Name () { return name_; } }; void load_lastruntime (::std::string filename); void save_lastruntime (::std::string& filename, time_t time); #endif