From 6c8511838ede3effc07437212dd72a1a36f5bd4f Mon Sep 17 00:00:00 2001 From: Kelvin Sherlock Date: Thu, 15 Jan 2015 14:11:55 -0500 Subject: [PATCH] root directory is 2, not 1. --- toolbox/fs_spec.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/toolbox/fs_spec.cpp b/toolbox/fs_spec.cpp index 7a8020e..1e0ae16 100644 --- a/toolbox/fs_spec.cpp +++ b/toolbox/fs_spec.cpp @@ -5,6 +5,8 @@ namespace OS { + const int RootPathID = 2; + std::deque FSSpecManager::_pathQueue; void FSSpecManager::Init() @@ -49,7 +51,9 @@ namespace OS { Init(); - int i = 1; + // this only works well for a small number of directories, + // which should be the common case. + int i = RootPathID; for (const auto &e : _pathQueue) { if (e.hash == hash && e.path == path) return i; @@ -82,7 +86,7 @@ namespace OS { Init(); - int i = 1; + int i = RootPathID; for (const auto &e : _pathQueue) { if (e.hash == hash && e.path == path) return i; @@ -102,10 +106,11 @@ namespace OS { Init(); - if (id < 1) return NullString; - if (id > _pathQueue.size()) return NullString; + id -= RootPathID; + if (id < 0) return NullString; + if (id >= _pathQueue.size()) return NullString; - return _pathQueue[id - 1].path; + return _pathQueue[id].path; } std::string FSSpecManager::ExpandPath(const std::string &path, int32_t id)