Added t8.pl that test case sensitivity issues

Made some change in the .cpp code in order to be able to test
the code when the file system is case sensitive
This commit is contained in:
Olivier Goffart 2014-07-07 13:00:38 +02:00
parent 3806905f5b
commit cbc7942a00
4 changed files with 124 additions and 2 deletions

110
csync/tests/ownCloud/t8.pl Executable file
View file

@ -0,0 +1,110 @@
#!/usr/bin/perl
#
# Test script for the ownCloud module of csync.
# This script requires a running ownCloud instance accessible via HTTP.
# It does quite some fancy tests and asserts the results.
#
# Copyright (C) by Olivier Goffart <ogoffart@woboq.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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#
use lib ".";
use Carp::Assert;
use File::Copy;
use ownCloud::Test;
use strict;
print "Hello, this is t8, a tester for syncing of files on a case sensitive FS\n";
# The test is run on a 'normal' file system, but we tell pwncloud that it is case preserving anyway
$ENV{OWNCLOUD_TEST_CASE_PRESERVING} = "1";
# FIXME! the code does not work with parallelism
$ENV{OWNCLOUD_MAX_PARALLEL}="1";
initTesting();
printInfo( "Syncing two files with the same name that differ with case" );
#create some files localy
my $tmpdir = "/tmp/t8/";
mkdir($tmpdir);
createLocalFile( $tmpdir . "HELLO.dat", 100 );
createLocalFile( $tmpdir . "Hello.dat", 150 );
createLocalFile( $tmpdir . "Normal.dat", 110 );
#put them in some directories
createRemoteDir( "dir" );
glob_put( "$tmpdir/*", "dir" );
csync();
# Check that only one of the two file was synced.
# The one that exist here is undefined, the current implementation will take the
# first one alphabetically, but the other one would also be fine. What's imporant
# is that there is only one.
assert( -e localDir() . 'dir/HELLO.dat' );
assert( !-e localDir() . 'dir/Hello.dat' );
printInfo( "Remove one file should remove it on the server and download the other one" );
unlink( localDir() . 'dir/HELLO.dat' );
csync();
assert( -e localDir() . 'dir/Hello.dat' );
assert( !-e localDir() . 'dir/HELLO.dat' );
assertLocalAndRemoteDir( '', 0);
printInfo( "Renaming one file to the same name as another one with different casing" );
moveRemoteFile( 'dir/Hello.dat', 'dir/NORMAL.dat');
csync();
#It should not have do the move
assert( -e localDir() . 'dir/Hello.dat' );
assert( !-e localDir() . 'dir/NORMAL.dat' );
assert( -e localDir() . 'dir/Normal.dat' );
printInfo( "Another directory with the same name but different casing is created" );
createRemoteDir( "DIR" );
glob_put( "$tmpdir/*", "DIR" );
csync();
assert( !-e localDir() . 'DIR' );
printInfo( "Remove the old dir localy" );
system("rm -r " . localDir() . "dir");
csync();
# now DIR was fetched
assert( -e localDir() . 'DIR' );
assert( -e localDir() . 'DIR/HELLO.dat' );
assert( !-e localDir() . 'DIR/Hello.dat' );
assert( !-e localDir() . 'dir' );
# dir/NORMAL.dat is still on the server
cleanup();
system("rm -r " . $tmpdir);

View file

@ -29,6 +29,7 @@
#include <QStack>
#include <QFileInfo>
#include <QDir>
namespace Mirall {
@ -369,6 +370,15 @@ bool OwncloudPropagator::localFileNameClash( const QString& relFile )
re = true;
}
}
#else
// On Linux, the file system is case sensitive, but this code is usefull for testing.
// Just check that there is no other file with the same name and different casing.
QFileInfo fileInfo(file);
const QString fn = fileInfo.fileName();
QStringList list = fileInfo.dir().entryList(QStringList() << fn);
if (list.count() > 1 || (list.count() == 1 && list[0] != fn)) {
re = true;
}
#endif
}
return re;

View file

@ -108,8 +108,7 @@ void PropagateLocalMkdir::start()
QDir newDir(_propagator->_localDir + _item._file);
QString newDirStr = QDir::toNativeSeparators(newDir.path());
if( Utility::fsCasePreserving() && newDir.exists() &&
_propagator->localFileNameClash(_item._file ) ) {
if( Utility::fsCasePreserving() && _propagator->localFileNameClash(_item._file ) ) {
qDebug() << "WARN: new directory to create locally already exists!";
done( SyncFileItem::NormalError, tr("Attention, possible case sensitivity clash with %1").arg(newDirStr) );
return;

View file

@ -342,6 +342,9 @@ bool Utility::fsCasePreserving()
bool re = false;
if( isWindows() || isMac() ) {
re = true;
} else {
static bool isTest = qgetenv("OWNCLOUD_TEST_CASE_PRESERVING").toInt();
re = isTest;
}
return re;
}