upload.cpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. #include "stdafx.h"
  2. #include "SpBase.h"
  3. //#include "SpIni.h"
  4. #include "upload.h"
  5. //#include <memutil.h>
  6. #include <fileutil.h>
  7. //#include <array.h>
  8. //#include <string>
  9. //#include "sstream"
  10. #ifdef RVC_OS_WIN
  11. #include "XZip.h"
  12. #include <tchar.h>
  13. #include "EventCode.h"
  14. #include <map>
  15. #else
  16. #include "XZipZilb.h"
  17. #include <regex>
  18. #include <errno.h>
  19. #include "EventCode.h"
  20. #endif // RVC_OS_WIN
  21. using namespace std;
  22. #ifdef RVC_OS_WIN
  23. #define FT_2000_1_1_0_0_0 125911584000000000UL
  24. #else
  25. //表示2000.1.1号time_t的值 0时区
  26. #define FT_2000_1_1_0_0_0 946684800
  27. #endif // RVC_OS_WIN
  28. #ifdef RVC_OS_WIN
  29. #else
  30. int changeFileAtt(const char* path)
  31. {
  32. struct stat attr_of_del;
  33. if (lstat(path, &attr_of_del) == 0)
  34. {
  35. //修改为775属性
  36. mode_t f_attrib = S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IXGRP | S_IROTH | S_IXOTH;
  37. if (chmod(path, f_attrib) != 0)
  38. {
  39. Dbg("set file attribute is fail,errno=%d, file=%s", errno, path);
  40. return -1;
  41. }
  42. return 0;
  43. }
  44. else {
  45. Dbg("get file attribute is fail,errno=%d, file=%s", errno, path);
  46. return -1;
  47. }
  48. }
  49. long getLinuxFileCTime(const char* fileName)
  50. {
  51. string strPath(fileName);
  52. int lastSplit = strPath.find_last_of(SPLIT_SLASH);
  53. string fileNameStr = strPath.substr(lastSplit + 1, strPath.length() - lastSplit);
  54. if (fileNameStr.length() >= 8)
  55. {
  56. regex e("^[0-9]+$");
  57. if (!std::regex_match(fileNameStr.substr(0,8), e, regex_constants::match_default)) {
  58. Dbg("file name format is wrong ,eg: 20201010***");
  59. return 0;
  60. }
  61. string fileDateStr = fileNameStr.substr(0, 4) + "-" + fileNameStr.substr(4, 2) + "-" + fileNameStr.substr(6, 2) + " 00:00:00";
  62. tm tm_time ;
  63. //Dbg("fileDateStr:%s", fileDateStr.c_str());
  64. strptime(fileDateStr.c_str(), "%Y-%m-%d %H:%M:%S", &tm_time);
  65. tm_time.tm_isdst = -1;
  66. //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);
  67. time_t ft = mktime(&tm_time);
  68. //Dbg("ft=%d", ft);
  69. if (ft == -1) {
  70. Dbg("file [%s] get time_t is -1", fileName);
  71. return 0;
  72. }
  73. else {
  74. long diff = ft - FT_2000_1_1_0_0_0;
  75. return diff;
  76. }
  77. }
  78. else
  79. {
  80. Dbg("file name format is wrong ");
  81. return 0;
  82. }
  83. }
  84. #endif // RVC_OS_WIN