2018-10-27 12:17:07 +02:00
// Copyright (C) 2013, The Duplicati Team
2013-04-22 21:20:14 +02:00
// http://www.duplicati.com, opensource@duplicati.com
//
// This library is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as
// published by the Free Software Foundation; either version 2.1 of the
// License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
using System ;
2018-11-02 22:13:25 +01:00
using Duplicati.Library.Common ;
2018-11-02 21:34:07 +01:00
using Duplicati.Library.Common.IO ;
2018-10-27 12:17:07 +02:00
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 ();
cmd . Transaction = null ;
}
}
}
2013-04-22 21:20:14 +02:00
}