| 41 | /** \fn StorageGroup::Init(const QString, const QString) |
| 42 | * \brief Initilizes the groupname, hostname, and dirlist |
| 43 | * |
| 44 | * First attempts to find the Storage Group defined with the specified name |
| 45 | * for the given host. If not found, checks for the named Storage Group, as |
| 46 | * defined across all hosts. If not found, tries the "Default" Storage Group |
| 47 | * for the given host. If not found, tries the "Default" Storage Group, as |
| 48 | * defined across all hosts. |
| 49 | * |
| 50 | * \param group The name of the Storage Group |
| 51 | * \param hostname The host whose Storage Group definition is desired |
| 52 | */ |
63 | | query.bindValue(":GROUP", m_groupname); |
64 | | if (!m_hostname.isEmpty()) |
65 | | query.bindValue(":HOSTNAME", m_hostname); |
| 63 | VERBOSE(VB_FILE, LOC + |
| 64 | QString("Unable to find any directories for the local " |
| 65 | "storage group '%1' on '%2', trying directories on " |
| 66 | "all hosts!").arg(group).arg(hostname)); |
| 67 | found = FindDirs(m_groupname, ""); |
| 68 | if (found) |
| 69 | { |
| 70 | m_hostname = ""; |
| 71 | m_hostname.detach(); |
| 72 | } |
84 | | "Default storage group, trying directories in all " |
85 | | "Default groups!").arg(m_groupname)); |
86 | | Init("Default", ""); |
87 | | return; |
88 | | } |
89 | | } |
90 | | else |
91 | | { |
92 | | do |
93 | | { |
94 | | dirname = query.value(0).toString(); |
95 | | dirname.replace(QRegExp("^\\s*"), ""); |
96 | | dirname.replace(QRegExp("\\s*$"), ""); |
97 | | if (dirname.right(1) == "/") |
98 | | dirname.remove(dirname.length() - 1, 1); |
99 | | m_dirlist << dirname; |
| 89 | "Default storage group on '%1', trying directories " |
| 90 | "in all Default groups!").arg(hostname)); |
| 91 | found = FindDirs("Default", ""); |
| 92 | if(found) |
| 93 | { |
| 94 | m_groupname = "Default"; |
| 95 | m_hostname = ""; |
| 96 | m_groupname.detach(); |
| 97 | m_hostname.detach(); |
| 98 | } |
| 122 | /** \fn StorageGroup::FindDirs(const QString, const QString) |
| 123 | * \brief Finds and initializes the directory list associated with the Storage |
| 124 | * Group |
| 125 | * |
| 126 | * This function should only be called by StorageGroup::Init(). |
| 127 | * |
| 128 | * \param group The name of the Storage Group |
| 129 | * \param hostname The host whose directory list should be checked, first |
| 130 | * \return true if directories were found |
| 131 | */ |
| 132 | bool StorageGroup::FindDirs(const QString group, const QString hostname) |
| 133 | { |
| 134 | bool found = false; |
| 135 | QString dirname; |
| 136 | MSqlQuery query(MSqlQuery::InitCon()); |
| 137 | |
| 138 | QString sql = "SELECT DISTINCT dirname " |
| 139 | "FROM storagegroup "; |
| 140 | |
| 141 | if (!group.isEmpty()) |
| 142 | { |
| 143 | sql.append("WHERE groupname = :GROUP"); |
| 144 | if (!hostname.isEmpty()) |
| 145 | sql.append(" AND hostname = :HOSTNAME"); |
| 146 | } |
| 147 | |
| 148 | query.prepare(sql); |
| 149 | if (!group.isEmpty()) |
| 150 | { |
| 151 | query.bindValue(":GROUP", group); |
| 152 | if (!hostname.isEmpty()) |
| 153 | query.bindValue(":HOSTNAME", hostname); |
| 154 | } |
| 155 | |
| 156 | if (!query.exec() || !query.isActive()) |
| 157 | MythDB::DBError("StorageGroup::StorageGroup()", query); |
| 158 | else if (query.next()) |
| 159 | { |
| 160 | do |
| 161 | { |
| 162 | dirname = query.value(0).toString(); |
| 163 | dirname.replace(QRegExp("^\\s*"), ""); |
| 164 | dirname.replace(QRegExp("\\s*$"), ""); |
| 165 | if (dirname.right(1) == "/") |
| 166 | dirname.remove(dirname.length() - 1, 1); |
| 167 | m_dirlist << dirname; |
| 168 | } |
| 169 | while (query.next()); |
| 170 | found = true; |
| 171 | } |
| 172 | |
| 173 | return found; |
| 174 | } |
| 175 | |