1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- #include "stdafx.h"
- #include "SpBase.h"
- //#include "SpIni.h"
- #include "upload.h"
- //#include <memutil.h>
- #include <fileutil.h>
- //#include <array.h>
- //#include <string>
- //#include "sstream"
- #ifdef RVC_OS_WIN
- #include "XZip.h"
- #include <tchar.h>
- #include "EventCode.h"
- #include <map>
- #else
- #include "XZipZilb.h"
- #include <regex>
- #include <errno.h>
- #include "EventCode.h"
- #endif // RVC_OS_WIN
- using namespace std;
- #ifdef RVC_OS_WIN
- #define FT_2000_1_1_0_0_0 125911584000000000UL
- #else
- //表示2000.1.1号time_t的值 0时区
- #define FT_2000_1_1_0_0_0 946684800
- #endif // RVC_OS_WIN
- #ifdef RVC_OS_WIN
- #else
- int changeFileAtt(const char* path)
- {
- struct stat attr_of_del;
- if (lstat(path, &attr_of_del) == 0)
- {
- //修改为775属性
- mode_t f_attrib = S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IXGRP | S_IROTH | S_IXOTH;
- if (chmod(path, f_attrib) != 0)
- {
- Dbg("set file attribute is fail,errno=%d, file=%s", errno, path);
- return -1;
- }
- return 0;
- }
- else {
- Dbg("get file attribute is fail,errno=%d, file=%s", errno, path);
- return -1;
- }
- }
- long getLinuxFileCTime(const char* fileName)
- {
- string strPath(fileName);
- int lastSplit = strPath.find_last_of(SPLIT_SLASH);
- string fileNameStr = strPath.substr(lastSplit + 1, strPath.length() - lastSplit);
- if (fileNameStr.length() >= 8)
- {
- regex e("^[0-9]+$");
- if (!std::regex_match(fileNameStr.substr(0,8), e, regex_constants::match_default)) {
- Dbg("file name format is wrong ,eg: 20201010***");
- return 0;
- }
- string fileDateStr = fileNameStr.substr(0, 4) + "-" + fileNameStr.substr(4, 2) + "-" + fileNameStr.substr(6, 2) + " 00:00:00";
- tm tm_time ;
- //Dbg("fileDateStr:%s", fileDateStr.c_str());
- strptime(fileDateStr.c_str(), "%Y-%m-%d %H:%M:%S", &tm_time);
- tm_time.tm_isdst = -1;
- //Dbg("tm_time %d%d%d %d:%d:%d", tm_time.tm_year + 1900, tm_time.tm_mon + 1, tm_time.tm_mday, tm_time.tm_hour, tm_time.tm_min, tm_time.tm_sec);
- time_t ft = mktime(&tm_time);
- //Dbg("ft=%d", ft);
- if (ft == -1) {
- Dbg("file [%s] get time_t is -1", fileName);
- return 0;
- }
- else {
- long diff = ft - FT_2000_1_1_0_0_0;
- return diff;
- }
- }
- else
- {
- Dbg("file name format is wrong ");
- return 0;
- }
- }
- #endif // RVC_OS_WIN
|