This is an automated email from the ASF dual-hosted git repository.

zwoop pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git

commit 3a3f286c79c6a6c8afda9f4acd36a6b8b0a93f97
Author: Leif Hedstrom <[email protected]>
AuthorDate: Fri May 24 17:11:25 2019 -0600

    Step 16: Removes createPathStr() and cleans up statFile()
---
 mgmt/Rollback.cc | 47 ++++++++---------------------------------------
 mgmt/Rollback.h  |  9 ++-------
 2 files changed, 10 insertions(+), 46 deletions(-)

diff --git a/mgmt/Rollback.cc b/mgmt/Rollback.cc
index 478d4de..5c8ec3e 100644
--- a/mgmt/Rollback.cc
+++ b/mgmt/Rollback.cc
@@ -34,12 +34,6 @@
 #include "FileManager.h"
 #include "ProxyConfig.h"
 
-#define MAX_VERSION_DIGITS 11
-#define DEFAULT_BACKUPS 2
-
-constexpr int ACTIVE_VERSION  = 0;
-constexpr int INVALID_VERSION = -1;
-
 #if HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC
 #define TS_ARCHIVE_STAT_MTIME(t) ((t).st_mtime * 1000000000 + 
(t).st_mtimespec.tv_nsec)
 #elif HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC
@@ -97,7 +91,7 @@ Rollback::Rollback(const char *fileName_, const char 
*configName_, bool root_acc
 
   // Check to make sure that our configuration file exists
   //
-  if (statFile(ACTIVE_VERSION, &fileInfo) < 0) {
+  if (statFile(&fileInfo) < 0) {
     // If we can't find an active version because there is none we have a hard 
failure.
     mgmt_fatal(0, "[RollBack::Rollback] Unable to find configuration file 
%s.\n\tStat failed : %s\n", fileName, strerror(errno));
 
@@ -114,45 +108,20 @@ Rollback::~Rollback()
   ats_free(fileName);
 }
 
-// Rollback::createPathStr(version_t version)
-//
-//   CALLEE DELETES STORAGE
-//
-char *
-Rollback::createPathStr(version_t version)
-{
-  int bufSize  = 0;
-  char *buffer = nullptr;
-  std::string sysconfdir(RecConfigReadConfigDir());
-  bufSize = sysconfdir.size() + fileNameLen + MAX_VERSION_DIGITS + 1;
-  buffer  = (char *)ats_malloc(bufSize);
-  Layout::get()->relative_to(buffer, bufSize, sysconfdir, fileName);
-  if (version != ACTIVE_VERSION) {
-    size_t pos = strlen(buffer);
-    snprintf(buffer + pos, bufSize - pos, "_%d", version);
-  }
-
-  return buffer;
-}
-
 //
 //
-// int Rollback::statFile(version_t)
+// int Rollback::statFile()
 //
 //  A wrapper for stat()
 //
 int
-Rollback::statFile(version_t version, struct stat *buf)
+Rollback::statFile(struct stat *buf)
 {
   int statResult;
+  std::string sysconfdir(RecConfigReadConfigDir());
+  std::string filePath = Layout::get()->relative_to(sysconfdir, fileName);
 
-  if (version == this->currentVersion) {
-    version = ACTIVE_VERSION;
-  }
-
-  ats_scoped_str filePath(createPathStr(version));
-
-  statResult = root_access_needed ? elevating_stat(filePath, buf) : 
stat(filePath, buf);
+  statResult = root_access_needed ? elevating_stat(filePath.c_str(), buf) : 
stat(filePath.c_str(), buf);
 
   return statResult;
 }
@@ -163,7 +132,7 @@ Rollback::setLastModifiedTime()
   struct stat fileInfo;
 
   // Now we need to get the modification time off of the new active file
-  if (statFile(ACTIVE_VERSION, &fileInfo) >= 0) {
+  if (statFile(&fileInfo) >= 0) {
     fileLastModified = TS_ARCHIVE_STAT_MTIME(fileInfo);
     return true;
   } else {
@@ -187,7 +156,7 @@ Rollback::checkForUserUpdate()
 
   ink_mutex_acquire(&fileAccessLock);
 
-  if (this->statFile(ACTIVE_VERSION, &fileInfo) < 0) {
+  if (this->statFile(&fileInfo) < 0) {
     ink_mutex_release(&fileAccessLock);
     return false;
   }
diff --git a/mgmt/Rollback.h b/mgmt/Rollback.h
index 3200824..2d4cba4 100644
--- a/mgmt/Rollback.h
+++ b/mgmt/Rollback.h
@@ -60,11 +60,7 @@ struct versionInfo {
 //    refers to a file with an _version which does not exist for the active
 //    version.
 //
-//  statFile(version_t, struct stat*) - a wrapper for stat that
-//    that stats the specified version
-//
-//  createPathStr(version_t) - creates a string to the specified
-//    version of the file.  CALLEE DELETES storage
+//  statFile(struct stat*) - a wrapper for stat(), using layout engine
 //
 class Rollback
 {
@@ -135,8 +131,7 @@ public:
   Rollback &operator=(const Rollback &) = delete;
 
 private:
-  int statFile(version_t version, struct stat *buf);
-  char *createPathStr(version_t version);
+  int statFile(struct stat *buf);
   ink_mutex fileAccessLock;
   char *fileName;
   char *fileBaseName;

Reply via email to