2025-03-13 23:06:32 +01:00
// Copyright (C) 2025, 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
2024-02-28 15:45:30 +01:00
// 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.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 ()
{
2025-03-14 12:13:17 +01:00
using ( var tr = m_connection . BeginTransaction ())
using ( var cmd = m_connection . CreateCommand ())
2016-09-15 11:39:27 +02:00
{
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
2025-03-14 12:13:17 +01:00
using ( var upcmd = m_connection . CreateCommand ())
2016-09-15 11:39:27 +02:00
{
2025-03-14 12:13:17 +01:00
2016-09-15 11:39:27 +02:00
upcmd . Transaction = tr ;
2025-03-14 12:13:17 +01:00
upcmd . ExecuteNonQuery ( FormatInvariant ( $@"CREATE TEMPORARY TABLE ""{tablename}"" (""ID"" INTEGER PRIMARY KEY, ""RealPath"" TEXT NOT NULL, ""Obfuscated"" TEXT NULL)" ));
upcmd . ExecuteNonQuery ( FormatInvariant ( $@"INSERT INTO ""{tablename}"" (""RealPath"") SELECT DISTINCT ""Path"" FROM ""File"" ORDER BY ""Path"" " ));
2025-04-02 13:31:31 +02:00
upcmd . SetCommandAndParameters ( FormatInvariant ( $@"UPDATE ""{tablename}"" SET ""Obfuscated"" = @StartPath || length(""RealPath"") || @DirSep || ""ID"" || (CASE WHEN substr(""RealPath"", length(""RealPath"")) = @DirSep THEN @DirSep ELSE @FileExt END) " ))
. SetParameterValue ( "@StartPath" , ! OperatingSystem . IsWindows () ? "/" : "X:\\" )
. SetParameterValue ( "@DirSep" , Util . DirectorySeparatorString )
. SetParameterValue ( "@FileExt" , ".bin" )
. ExecuteNonQuery ();
2025-03-13 23:06:32 +01: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())
{
2025-04-02 13:31:31 +02:00
upcmd.SetCommandAndParameters(@"UPDATE ""LogData"" SET ""Message"" = replace(""Message"", @RealPath, @Obfuscated), ""Exception"" = replace(""Exception"", @RealPath, @Obfuscated)")
.SetParameterValue("@RealPath", rd.GetValue(0))
.SetParameterValue("@Obfuscated", rd.GetValue(1))
.ExecuteNonQuery();
2016-09-15 11:39:27 +02:00
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
2025-03-13 23:06:32 +01:00
cmd . ExecuteNonQuery ( @"UPDATE ""LogData"" SET ""Message"" = 'ERASED!' WHERE ""Message"" LIKE '%/%' OR ""Message"" LIKE '%:\%' " );
cmd . ExecuteNonQuery ( @"UPDATE ""LogData"" SET ""Exception"" = 'ERASED!' WHERE ""Exception"" LIKE '%/%' OR ""Exception"" LIKE '%:\%' " );
2019-07-30 21:03:58 -07:00
2024-05-22 00:11:03 +02:00
cmd . ExecuteNonQuery ( @"UPDATE ""Configuration"" SET ""Value"" = 'ERASED!' WHERE ""Key"" = 'passphrase' " );
2018-06-14 10:12:24 +02:00
2025-03-14 12:13:17 +01:00
cmd . ExecuteNonQuery ( FormatInvariant ( $@"CREATE TABLE ""FixedFile"" AS SELECT ""B"".""ID"" AS ""ID"", ""A"".""Obfuscated"" AS ""Path"", ""B"".""BlocksetID"" AS ""BlocksetID"", ""B"".""MetadataID"" AS ""MetadataID"" FROM ""{tablename}"" ""A"", ""File"" ""B"" WHERE ""A"".""RealPath"" = ""B"".""Path"" " ));
2019-04-09 21:12:25 +02:00
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"" " );
2025-03-14 12:13:17 +01:00
cmd . ExecuteNonQuery ( FormatInvariant ( $@"DROP TABLE IF EXISTS ""{tablename}"" " ));
using ( new Logging . Timer ( LOGTAG , "CommitUpdateBugReport" , "CommitUpdateBugReport" ))
2016-09-15 11:39:27 +02:00
tr . Commit ();
2025-03-14 12:13:17 +01:00
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
}