2024-02-28 15:45:30 +01:00
// Copyright (C) 2024, The Duplicati Team
// https://duplicati.com, hello@duplicati.com
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
2013-04-22 21:20:14 +02:00
using System ;
2024-02-28 15:45:30 +01:00
using Duplicati.Library.Common ;
using Duplicati.Library.Common.IO ;
2013-05-08 20:17:07 +02:00
namespace Duplicati.Library.Main.Database
2013-04-22 21:20:14 +02:00
{
2016-09-15 11:39:27 +02:00
internal class LocalBugReportDatabase : LocalDatabase
{
2018-03-12 14:07:11 +01:00
/// <summary>
/// The tag used for logging
/// </summary>
private static readonly string LOGTAG = Logging . Log . LogTagFromType ( typeof ( LocalBugReportDatabase ));
2016-09-15 11:39:27 +02:00
public LocalBugReportDatabase ( string path )
: base ( path , "BugReportCreate" , false )
{
2016-04-06 20:40:34 +02:00
ShouldCloseConnection = true ;
2016-09-15 11:39:27 +02:00
}
2013-04-22 21:20:14 +02:00
2016-09-15 11:39:27 +02:00
public void Fix ()
{
using ( var tr = m_connection . BeginTransaction ())
using ( var cmd = m_connection . CreateCommand ())
{
cmd . Transaction = tr ;
2013-09-25 23:32:37 +02:00
var tablename = "PathMap-" + Library . Utility . Utility . ByteArrayAsHexString ( Guid . NewGuid (). ToByteArray ());
2018-06-14 10:12:24 +02:00
// TODO: Rewrite this to use PathPrefix
// TODO: Needs to be much faster
2016-09-15 11:39:27 +02:00
using ( var upcmd = m_connection . CreateCommand ())
{
upcmd . Transaction = tr ;
2013-09-25 23:32:37 +02:00
upcmd . ExecuteNonQuery ( string . Format ( @"CREATE TEMPORARY TABLE ""{0}"" (""ID"" INTEGER PRIMARY KEY, ""RealPath"" TEXT NOT NULL, ""Obfuscated"" TEXT NULL)" , tablename ));
upcmd . ExecuteNonQuery ( string . Format ( @"INSERT INTO ""{0}"" (""RealPath"") SELECT DISTINCT ""Path"" FROM ""File"" ORDER BY ""Path"" " , tablename ));
2018-11-03 09:26:04 +01:00
upcmd . ExecuteNonQuery ( string . Format ( @"UPDATE ""{0}"" SET ""Obfuscated"" = ? || length(""RealPath"") || ? || ""ID"" || (CASE WHEN substr(""RealPath"", length(""RealPath"")) = ? THEN ? ELSE ? END) " , tablename ), Platform . IsClientPosix ? "/" : "X:\\" , Util . DirectorySeparatorString , Util . DirectorySeparatorString , Util . DirectorySeparatorString , ".bin" );
2013-09-25 23:32:37 +02:00
2017-02-02 22:23:54 +01:00
/*long id = 1;
2016-09-15 11:39:27 +02:00
using(var rd = cmd.ExecuteReader(string.Format(@"SELECT ""RealPath"", ""Obfuscated"" FROM ""{0}"" ", tablename)))
while(rd.Read())
{
upcmd.ExecuteNonQuery(@"UPDATE ""LogData"" SET ""Message"" = replace(""Message"", ?, ?), ""Exception"" = replace(""Exception"", ?, ?)", rd.GetValue(0), rd.GetValue(1), rd.GetValue(0), rd.GetValue(1) );
id++;
}
2017-02-02 22:23:54 +01:00
*/
2016-09-15 11:39:27 +02:00
}
2013-04-22 21:20:14 +02:00
2016-09-15 11:39:27 +02:00
cmd . ExecuteNonQuery ( @"UPDATE ""LogData"" SET ""Message"" = ""ERASED!"" WHERE ""Message"" LIKE ""%/%"" OR ""Message"" LIKE ""%:\%"" " );
2019-07-30 21:07:17 -07:00
cmd . ExecuteNonQuery ( @"UPDATE ""LogData"" SET ""Exception"" = ""ERASED!"" WHERE ""Exception"" LIKE ""%/%"" OR ""Exception"" LIKE ""%:\%"" " );
2019-07-30 21:03:58 -07:00
cmd . ExecuteNonQuery ( @"UPDATE ""Configuration"" SET ""Value"" = ""ERASED!"" WHERE ""Key"" = ""passphrase"" " );
2018-06-14 10:12:24 +02:00
2019-04-09 21:12:25 +02:00
cmd . ExecuteNonQuery ( string . Format ( @"CREATE TABLE ""FixedFile"" AS SELECT ""B"".""ID"" AS ""ID"", ""A"".""Obfuscated"" AS ""Path"", ""B"".""BlocksetID"" AS ""BlocksetID"", ""B"".""MetadataID"" AS ""MetadataID"" FROM ""{0}"" ""A"", ""File"" ""B"" WHERE ""A"".""RealPath"" = ""B"".""Path"" " , tablename ));
cmd . ExecuteNonQuery ( @"DROP VIEW ""File"" " );
2019-07-30 21:03:58 -07:00
cmd . ExecuteNonQuery ( @"DROP TABLE ""FileLookup"" " );
2018-06-14 10:12:24 +02:00
cmd . ExecuteNonQuery ( @"DROP TABLE ""PathPrefix"" " );
2013-09-25 23:32:37 +02:00
cmd . ExecuteNonQuery ( string . Format ( @"DROP TABLE IF EXISTS ""{0}"" " , tablename ));
2018-03-12 14:07:11 +01:00
using ( new Logging . Timer ( LOGTAG , "CommitUpdateBugReport" , "CommitUpdateBugReport" ))
2016-09-15 11:39:27 +02:00
tr . Commit ();
2024-02-28 15:45:30 +01:00
cmd . Transaction = null ;
2023-12-13 09:27:51 +01:00
cmd . ExecuteNonQuery ( "VACUUM" );
2016-09-15 11:39:27 +02:00
}
}
}
2013-04-22 21:20:14 +02:00
}