2013-04-22 21:20:14 +02:00
// Copyright (C) 2013, The Duplicati Team
// 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 ;
2013-05-08 20:17:07 +02:00
namespace Duplicati.Library.Main.Database
2013-04-22 21:20:14 +02:00
{
2013-08-22 20:52:54 +02:00
internal class LocalBugReportDatabase : LocalDatabase
2013-04-22 21:20:14 +02:00
{
public LocalBugReportDatabase ( string path )
: base ( path , "BugReportCreate" )
{
}
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 ());
2013-04-22 21:20:14 +02:00
using ( var upcmd = m_connection . CreateCommand ())
{
2013-09-25 23:32:37 +02:00
2013-04-22 21:20:14 +02:00
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 ));
upcmd . ExecuteNonQuery ( string . Format ( @"UPDATE ""{0}"" SET ""Obfuscated"" = ? || length(""RealPath"") || ? || ""ID"" || (CASE WHEN substr(""RealPath"", length(""RealPath"")) = ? THEN ? ELSE ? END) " , tablename ), Library . Utility . Utility . IsClientLinux ? "/" : "X:\\" , Library . Utility . Utility . DirectorySeparatorString , Library . Utility . Utility . DirectorySeparatorString , Library . Utility . Utility . DirectorySeparatorString , ".bin" );
2013-04-22 21:20:14 +02:00
long id = 1 ;
2013-09-25 23:32:37 +02:00
using ( var rd = cmd . ExecuteReader ( string . Format ( @"SELECT ""RealPath"", ""Obfuscated"" FROM ""{0}"" " , tablename )))
2013-04-22 21:20:14 +02:00
while ( rd . Read ())
{
2013-09-25 23:32:37 +02:00
upcmd . ExecuteNonQuery ( @"UPDATE ""LogData"" SET ""Message"" = replace(""Message"", ?, ?), ""Exception"" = replace(""Exception"", ?, ?)" , rd . GetValue ( 0 ), rd . GetValue ( 1 ), rd . GetValue ( 0 ), rd . GetValue ( 1 ) );
2013-04-22 21:20:14 +02:00
id ++;
}
}
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 ""%:\%"" " );
2013-09-25 23:32:37 +02:00
cmd . ExecuteNonQuery ( string . Format ( @"UPDATE ""File"" SET ""Path"" = (SELECT ""Obfuscated"" FROM ""{0}"" WHERE ""Path"" = ""RealPath"") " , tablename ));
2013-04-22 21:20:14 +02:00
2013-09-25 23:32:37 +02:00
cmd . ExecuteNonQuery ( string . Format ( @"DROP TABLE IF EXISTS ""{0}"" " , tablename ));
2013-06-09 16:26:08 +02:00
using ( new Logging . Timer ( "CommitUpdateBugReport" ))
tr . Commit ();
2013-04-22 21:20:14 +02:00
cmd . Transaction = null ;
cmd . ExecuteNonQuery ( "VACUUM" );
}
}
}
}