Compare commits

...

4 Commits

Author SHA1 Message Date
Liru Færs
64ed6e99f0 Fix [NAME] appearing in certain i18n notifications instead of slurls
Thanks for catching this, Nai
2020-04-19 20:12:23 -04:00
Liru Færs
33d3bb2870 [Chat Logs] When migrating file to new name, respect possible new name file
If a new name file exists, copy its contents into our currently tracked
file, because we update our tracked file, the new file can only contain
more recent text (unless a name change back and forth and back happened
since last run, but then the out of order text isn't entirely our fault)

So we copy the new file's text to the bottom of our old file and then
remove the new file, so we can rename our old tracked file to the updated
name.

If we cannot perform the copy, or the delete, we bypass the migration,
leaving our old tracked file as a remnant and begin to track the new name
file because that is more proper than clinging to the old one, and thus
no history is lost to failure.
2020-04-19 20:04:25 -04:00
Liru Færs
4df2193a4c [Chat Logs] Always read from name cache on start to try to update ID Map 2020-04-19 16:40:17 -04:00
Liru Færs
343be08467 [Chat Logs] Break out migrateFile from makeLogFileName for use elsewhere 2020-04-19 15:50:50 -04:00
5 changed files with 58 additions and 25 deletions

View File

@@ -61,12 +61,35 @@ std::string LLLogChat::makeLogFileNameInternal(std::string filename)
return get_log_dir_file(filename + ".txt");
}
bool LLLogChat::migrateFile(const std::string& old_name, const std::string& filename)
{
std::string oldfile = makeLogFileNameInternal(old_name);
if (!LLFile::isfile(oldfile)) return false; // An old file by this name doesn't exist
if (LLFile::isfile(filename)) // A file by the new name also exists, but wasn't being tracked yet
{
auto&& new_untracked_log = llifstream(filename);
auto&& tracked_log = llofstream(oldfile, llofstream::out|llofstream::app);
// Append new to old and find out if it failed
bool failed = !(tracked_log << new_untracked_log.rdbuf());
// Close streams
new_untracked_log.close();
tracked_log.close();
if (failed || LLFile::remove(filename)) // Delete the untracked new file so that reclaiming its name won't fail
return true; // We failed to remove it or update the old file, let's just use the new file and leave the old one alone
}
LLFile::rename(oldfile, filename); // Move the existing file to the new name
return true; // Report success
}
static LLSD sIDMap;
static std::string get_ids_map_file() { return get_log_dir_file("ids_to_names.json"); }
void LLLogChat::initializeIDMap()
{
const auto map_file = get_ids_map_file();
bool write = true; // Do we want to write back to map_file?
if (LLFile::isfile(map_file)) // If we've already made this file, load our map from it
{
if (auto&& fstr = llifstream(map_file))
@@ -74,13 +97,28 @@ void LLLogChat::initializeIDMap()
LLSDSerialize::fromNotation(sIDMap, fstr, LLSDSerialize::SIZE_UNLIMITED);
fstr.close();
}
write = false; // Don't write what we just read
}
else if (gCacheName) // Load what we can from name cache to initialize the map file
{
for (const auto& r : gCacheName->getReverseMap()) // For every name id pair
if (LLFile::isfile(makeLogFileNameInternal(r.first))) // If there's a log file for them
sIDMap[r.second.asString()] = r.first; // Add them to the map
if (gCacheName) // Load what we can from name cache to initialize or update the map and its file
{
bool empty = sIDMap.size() == 0; // Opt out of searching the map for IDs we added if we started with none
for (const auto& r : gCacheName->getReverseMap()) // For every name id pair
{
const auto id = r.second.asString();
const auto& name = r.first;
const auto filename = makeLogFileNameInternal(name);
bool id_known = !empty && sIDMap.has(id); // Is this ID known?
if (id_known ? name != sIDMap[id].asStringRef() // If names don't match
&& migrateFile(sIDMap[id].asStringRef(), filename) // Do we need to migrate an existing log?
: LLFile::isfile(filename)) // Otherwise if there's a log file for them but they're not in the map yet
{
if (id_known) write = true; // We updated, write
sIDMap[id] = name; // Add them to the map
}
}
if (write)
if (auto&& fstr = llofstream(map_file))
{
LLSDSerialize::toPrettyNotation(sIDMap, fstr);
@@ -101,21 +139,15 @@ std::string LLLogChat::makeLogFileName(const std::string& username, const LLUUID
const bool empty = !entry.size();
if (empty || entry != name) // If we haven't seen this entry yet, or the name is different than we remember
{
const auto migrateFile = [&filename](const std::string& name) {
std::string oldname = makeLogFileNameInternal(name);
if (!LLFile::isfile(oldname)) return false; // An old file by this name doesn't exist
LLFile::rename(oldname, filename); // Move the existing file to the new name
return true; // Report success
};
if (empty) // We didn't see this entry on load
{
// Ideally, we would look up the old names here via server request
// In lieu of that, our reverse cache has old names and new names that we've gained since our initialization of the ID map
for (const auto& r : gCacheName->getReverseMap())
if (r.second == id && migrateFile(r.first))
if (r.second == id && migrateFile(r.first, filename))
break;
}
else migrateFile(entry.asStringRef()); // We've seen this entry before, migrate old file if it exists
else migrateFile(entry.asStringRef(), filename); // We've seen this entry before, migrate old file if it exists
entry = name; // Update the entry to point to the new name

View File

@@ -53,6 +53,7 @@ public:
std::function<void (ELogLineType, const std::string&)> callback);
private:
static std::string makeLogFileNameInternal(std::string filename);
static bool migrateFile(const std::string& old_name, const std::string& filename);
static void cleanFileName(std::string& filename);
};

View File

@@ -2156,7 +2156,7 @@ Offer a teleport?<tag>Best&#xE4;tigen</tag><form name="form">
<button name="GoNow..." text="Jetzt gehen..."/>
</form></notification>
<notification name="OfferFriendship">[NAME] bietet Ihnen die Freundschaft an.
<notification name="OfferFriendship">[NAME_SLURL] bietet Ihnen die Freundschaft an.
[MESSAGE]
@@ -2169,7 +2169,7 @@ Offer a teleport?<tag>Best&#xE4;tigen</tag><form name="form">
<notification name="FriendshipOffered">Sie haben [TO_NAME] die Freundschaft angeboten.</notification>
<notification name="OfferFriendshipNoMessage">[NAME] bietet Ihnen die Freundschaft an.
<notification name="OfferFriendshipNoMessage">[NAME_SLURL] bietet Ihnen die Freundschaft an.
(Sie werden dadurch den gegenseitigen Online-Status sehen k&#xF6;nnen.)<form name="form">
<button name="Accept" text="Akzeptieren"/>
@@ -2178,9 +2178,9 @@ Offer a teleport?<tag>Best&#xE4;tigen</tag><form name="form">
<button name="Profile" text="Profil"/>
</form></notification>
<notification name="FriendshipAccepted">[NAME] hat Ihr Freundschaftsangebot akzeptiert.</notification>
<notification name="FriendshipAccepted">[NAME_SLURL] hat Ihr Freundschaftsangebot akzeptiert.</notification>
<notification name="FriendshipDeclined">[NAME] hat Ihr Freundschaftsangebot abgelehnt.</notification>
<notification name="FriendshipDeclined">[NAME_SLURL] hat Ihr Freundschaftsangebot abgelehnt.</notification>
<notification name="FriendshipDissolved">[NAME] hat Ihr Freundschaftsangebot abgelehnt.</notification>

View File

@@ -2788,7 +2788,7 @@ Riprova tra qualche istante.
</form>
</notification>
<notification name="OfferFriendship">
[NAME] ti ha offerto la sua amicizia.
[NAME_SLURL] ti ha offerto la sua amicizia.
[MESSAGE]
@@ -2799,7 +2799,7 @@ Riprova tra qualche istante.
</form>
</notification>
<notification name="OfferFriendshipNoMessage">
[NAME] ti ha offerto la sua amicizia.
[NAME_SLURL] ti ha offerto la sua amicizia.
(Di default, potrete vedervi reciprocamente online.)
<form name="form">
@@ -2808,10 +2808,10 @@ Riprova tra qualche istante.
</form>
</notification>
<notification name="FriendshipAccepted">
[NAME] ha accettato la tua offerta di amicizia.
[NAME_SLURL] ha accettato la tua offerta di amicizia.
</notification>
<notification name="FriendshipDeclined">
[NAME] ha rifiutato la tua offerta di amicizia.
[NAME_SLURL] ha rifiutato la tua offerta di amicizia.
</notification>
<notification name="OfferCallingCard">
[NAME] ti ha offerto il suo biglietto da visita.

View File

@@ -3556,7 +3556,7 @@ No entanto, esta região tem conteúdo acessível apenas para adultos.
</notification>
<notification name="OfferFriendship">
[NAME] está lhe oferecendo sua amizade
[NAME_SLURL] está lhe oferecendo sua amizade
[MESSAGE]
@@ -3572,7 +3572,7 @@ No entanto, esta região tem conteúdo acessível apenas para adultos.
</notification>
<notification name="OfferFriendshipNoMessage">
[NAME] está lhe oferecendo sua amizade.
[NAME_SLURL] está lhe oferecendo sua amizade.
(Por definição vocês serão capazes de ver um ao outro online)
<form name="form">
@@ -3582,11 +3582,11 @@ No entanto, esta região tem conteúdo acessível apenas para adultos.
</notification>
<notification name="FriendshipAccepted">
[NAME] aceitou seu convite de amizade.
[NAME_SLURL] aceitou seu convite de amizade.
</notification>
<notification name="FriendshipDeclined">
[NAME] recusou seu convite de amizade
[NAME_SLURL] recusou seu convite de amizade
</notification>