Database: Change path for new dbs to .sync_* #5904

This is to avoid issues on OSX, where the ._ prefix has special meaning.

Originally (before 2.3.2) ._ was necessary to guarantee exclusion. But
since then the .sync_ prefix is excluded as well.

This does not affect existing database files.
This commit is contained in:
Christian Kamm 2018-12-18 10:10:19 +01:00 committed by Kevin Ottens
parent 30294e0c9a
commit 69144566ce
No known key found for this signature in database
GPG key ID: 074BBBCB8DECC9E2
8 changed files with 15 additions and 34 deletions

View file

@ -55,8 +55,8 @@ Identifying Basic Functionality Problems
---------------------
If you see this error message stop your client, delete the
``._sync_xxxxxxx.db`` file, and then restart your client.
There is a hidden ``._sync_xxxxxxx.db`` file inside the folder of every account
``.sync_xxxxxxx.db`` file, and then restart your client.
There is a hidden ``.sync_xxxxxxx.db`` file inside the folder of every account
configured on your client.
.. NOTE::

View file

@ -109,7 +109,7 @@ QString SyncJournalDb::makeDbName(const QString &localPath,
const QString &remotePath,
const QString &user)
{
QString journalPath = QLatin1String("._sync_");
QString journalPath = QLatin1String(".sync_");
QString key = QString::fromUtf8("%1@%2:%3").arg(user, remoteUrl.toString(), remotePath);
@ -117,15 +117,6 @@ QString SyncJournalDb::makeDbName(const QString &localPath,
journalPath.append(ba.left(6).toHex());
journalPath.append(".db");
// If the journal doesn't exist and we can't create a file
// at that location, try again with a journal name that doesn't
// have the ._ prefix.
//
// The disadvantage of that filename is that it will only be ignored
// by client versions >2.3.2.
//
// See #5633: "._*" is often forbidden on samba shared folders.
// If it exists already, the path is clearly usable
QFile file(QDir(localPath).filePath(journalPath));
if (file.exists()) {
@ -140,19 +131,8 @@ QString SyncJournalDb::makeDbName(const QString &localPath,
return journalPath;
}
// Can we create it if we drop the underscore?
QString alternateJournalPath = journalPath.mid(2).prepend(".");
QFile file2(QDir(localPath).filePath(alternateJournalPath));
if (file2.open(QIODevice::ReadWrite)) {
// The alternative worked, use it
qCInfo(lcDb) << "Using alternate database path" << alternateJournalPath;
file2.close();
file2.remove();
return alternateJournalPath;
}
// Neither worked, just keep the original and throw errors later
qCWarning(lcDb) << "Could not find a writable database path" << file.fileName();
// Error during creation, just keep the original and throw errors later
qCWarning(lcDb) << "Could not find a writable database path" << file.fileName() << file.errorString();
return journalPath;
}

View file

@ -741,7 +741,7 @@ void Folder::wipe()
// Delete files that have been partially downloaded.
slotDiscardDownloadProgress();
//Unregister the socket API so it does not keep the ._sync_journal file open
//Unregister the socket API so it does not keep the .sync_journal file open
FolderMan::instance()->socketApi()->slotUnregisterPath(alias());
_journal.close(); // close the sync journal

View file

@ -270,12 +270,13 @@ void FolderMan::setupFoldersHelper(QSettings &settings, AccountStatePtr account,
continue;
}
// Migration: ._ files sometimes don't work
// So if the configured journalPath is the default one ("._sync_*.db")
// Migration: ._ files sometimes can't be created.
// So if the configured journalPath has a dot-underscore ("._sync_*.db")
// but the current default doesn't have the underscore, switch to the
// new default. See SyncJournalDb::makeDbName().
// new default if no db exists yet.
if (folderDefinition.journalPath.startsWith("._sync_")
&& defaultJournalPath.startsWith(".sync_")) {
&& defaultJournalPath.startsWith(".sync_")
&& !QFile::exists(folderDefinition.absoluteJournalPath())) {
folderDefinition.journalPath = defaultJournalPath;
}

View file

@ -455,7 +455,7 @@ sub traverse( $$;$ )
$isHere = 1 if( $acceptConflicts && !$isHere && $f =~ /conflicted copy/ );
$isHere = 1 if( $f =~ /\.csync/ );
$isHere = 1 if( $f =~ /\._sync_/ );
$isHere = 1 if( $f =~ /\.sync_/ );
assert( $isHere, "Filename local, but not remote: $f" );
}

View file

@ -176,7 +176,7 @@ assertLocalAndRemoteDir( 'remoteToLocal1', 1);
printInfo("simulate a owncloud 5 update by removing all the fileid");
## simulate a owncloud 5 update by removing all the fileid
system( "sqlite3 " . localDir() . "._sync_*.db \"UPDATE metadata SET fileid='';\"");
system( "sqlite3 " . localDir() . ".sync_*.db \"UPDATE metadata SET fileid='';\"");
#refresh the ids
csync();
assertLocalAndRemoteDir( 'remoteToLocal1', 1);

View file

@ -61,7 +61,7 @@ sub getETagFromJournal($$)
{
my ($name,$num) = @_;
my $sql = "sqlite3 " . localDir() . "._sync_*.db \"SELECT md5 FROM metadata WHERE path='$name';\"";
my $sql = "sqlite3 " . localDir() . ".sync_*.db \"SELECT md5 FROM metadata WHERE path='$name';\"";
open(my $fh, '-|', $sql) or die $!;
my $etag = <$fh>;
close $fh;

View file

@ -920,7 +920,7 @@ public:
_account->setDavDisplayName("fakename");
_account->setServerVersion("10.0.0");
_journalDb = std::make_unique<OCC::SyncJournalDb>(localPath() + "._sync_test.db");
_journalDb = std::make_unique<OCC::SyncJournalDb>(localPath() + ".sync_test.db");
_syncEngine = std::make_unique<OCC::SyncEngine>(_account, localPath(), "", _journalDb.get());
// Ignore temporary files from the download. (This is in the default exclude list, but we don't load it)
_syncEngine->excludedFiles().addManualExclude("]*.~*");