Merge lp:~facundo/ubuntuone-client/lr-stop-nonutf8 into lp:ubuntuone-client

Proposed by Facundo Batista
Status: Merged
Approved by: Facundo Batista
Approved revision: 1111
Merged at revision: 1119
Proposed branch: lp:~facundo/ubuntuone-client/lr-stop-nonutf8
Merge into: lp:ubuntuone-client
Diff against target: 117 lines (+66/-6)
2 files modified
tests/syncdaemon/test_localrescan.py (+32/-1)
ubuntuone/syncdaemon/local_rescan.py (+34/-5)
To merge this branch: bzr merge lp:~facundo/ubuntuone-client/lr-stop-nonutf8
Reviewer Review Type Date Requested Status
Facundo Batista (community) Approve
Natalia Bidart (community) Approve
Review via email: mp+72452@code.launchpad.net

Commit message

Ignore non utf8 paths in LR (LP: #696901).

Description of the change

Ignore non utf8 paths in LR.

The one that should check if the path is valid is LocalRescan. It can't be done in the signals processors (that are close to real validation, in the freeze_commit stage).

The reason for this is that if LR finds an invalid path it needs to ignore it; in files there is no problem, but for directories it shouldn't scan that directory later.

So, I added a function in LR, very similar to the one in in platform/linux/filesystem_notification.py; didn't use that because this is more platform independant, will all go away when put everything in unicode, and most importantly because don't want to send invalid notifications and don't write in the invalid log for *every* local rescan.

Tests included, and also added logging when ignoring the path because of symlink.

To post a comment you must log in.
Revision history for this message
Natalia Bidart (nataliabidart) wrote :

Looks great!

review: Approve
Revision history for this message
Facundo Batista (facundo) wrote :

Approving with one review.

review: Approve
Revision history for this message
Ubuntu One Auto Pilot (otto-pilot) wrote :
Download full text (252.9 KiB)

The attempt to merge lp:~facundo/ubuntuone-client/lr-stop-nonutf8 into lp:ubuntuone-client failed. Below is the output from the failed tests.

/usr/bin/gnome-autogen.sh
checking for autoconf >= 2.53...
  testing autoconf2.50... not found.
  testing autoconf... found 2.67
checking for automake >= 1.10...
  testing automake-1.11... found 1.11.1
checking for libtool >= 1.5...
  testing libtoolize... found 2.2.6b
checking for intltool >= 0.30...
  testing intltoolize... found 0.41.1
checking for pkg-config >= 0.14.0...
  testing pkg-config... found 0.25
checking for gtk-doc >= 1.0...
  testing gtkdocize... found 1.17
Checking for required M4 macros...
Checking for forbidden M4 macros...
Processing ./configure.ac
Running libtoolize...
libtoolize: putting auxiliary files in `.'.
libtoolize: copying file `./ltmain.sh'
libtoolize: putting macros in AC_CONFIG_MACRO_DIR, `m4'.
libtoolize: copying file `m4/libtool.m4'
libtoolize: copying file `m4/ltoptions.m4'
libtoolize: copying file `m4/ltsugar.m4'
libtoolize: copying file `m4/ltversion.m4'
libtoolize: copying file `m4/lt~obsolete.m4'
Running intltoolize...
Running gtkdocize...
Running aclocal-1.11...
Running autoconf...
Running autoheader...
Running automake-1.11...
Running ./configure --enable-gtk-doc --enable-debug ...
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... no
checking for mawk... mawk
checking whether make sets $(MAKE)... yes
checking for style of include used by make... GNU
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking dependency style of gcc... gcc3
checking for library containing strerror... none required
checking for gcc... (cached) gcc
checking whether we are using the GNU C compiler... (cached) yes
checking whether gcc accepts -g... (cached) yes
checking for gcc option to accept ISO C89... (cached) none needed
checking dependency style of gcc... (cached) gcc3
checking build system type... i686-pc-linux-gnu
checking host system type... i686-pc-linux-gnu
checking for a sed that does not truncate output... /bin/sed
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for fgrep... /bin/grep -F
checking for ld used by gcc... /usr/bin/ld
checking if the linker (/usr/bin/ld) is GNU ld... yes
checking for BSD- or MS-compatible name lister (nm)... /usr/bin/nm -B
checking the name lister (/usr/bin/nm -B) interface... BSD nm
checking whether ln -s works... yes
checking the maximum length of command line arguments... 1572864
checking whether the shell understands some XSI constructs... yes
checking whether the shell understands "+="... yes
checking for /usr/bin/ld option to reload object files... -r
checking for objdump... objdump
checking how to ...

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'tests/syncdaemon/test_localrescan.py'
--- tests/syncdaemon/test_localrescan.py 2011-08-12 15:26:13 +0000
+++ tests/syncdaemon/test_localrescan.py 2011-08-22 15:52:23 +0000
@@ -1,7 +1,7 @@
1# Author: Facundo Batista <facundo@canonical.com>1# Author: Facundo Batista <facundo@canonical.com>
2# Author: Natalia Bidart <natalia.bidart@canonical.com>2# Author: Natalia Bidart <natalia.bidart@canonical.com>
3#3#
4# Copyright 2009 Canonical Ltd.4# Copyright 2009-2011 Canonical Ltd.
5#5#
6# This program is free software: you can redistribute it and/or modify it6# This program is free software: you can redistribute it and/or modify it
7# under the terms of the GNU General Public License version 3, as published7# under the terms of the GNU General Public License version 3, as published
@@ -617,6 +617,37 @@
617617
618 yield self.lr.start()618 yield self.lr.start()
619 self.assertEqual(self.eq.pushed, [])619 self.assertEqual(self.eq.pushed, [])
620 self.assertTrue(self.handler.check_info("Ignoring path",
621 "symlink", symlpath))
622
623 @skipIfOS('win32', "Windows paths are already unicode, "
624 "can't make this explode there")
625 @defer.inlineCallbacks
626 def test_disc_non_utf8_file(self):
627 """Test having a utf8 file."""
628 # create a broken path
629 path = os.path.join(self.share.path, "non utf8 \xff path")
630 with open_file(path, "w") as fh:
631 fh.write("broken")
632
633 yield self.lr.start()
634 self.assertEqual(self.eq.pushed, [])
635 self.assertTrue(self.handler.check_info("Ignoring path",
636 "invalid (non utf8)"))
637
638 @skipIfOS('win32', "Windows paths are already unicode, "
639 "can't make this explode there")
640 @defer.inlineCallbacks
641 def test_disc_non_utf8_dir(self):
642 """Test having a utf8 dir."""
643 # create a broken path
644 path = os.path.join(self.share.path, "non utf8 \xff path")
645 make_dir(path)
646
647 yield self.lr.start()
648 self.assertEqual(self.eq.pushed, [])
649 self.assertTrue(self.handler.check_info("Ignoring path",
650 "invalid (non utf8)"))
620651
621 @defer.inlineCallbacks652 @defer.inlineCallbacks
622 def test_disc_more_dir_normal(self):653 def test_disc_more_dir_normal(self):
623654
=== modified file 'ubuntuone/syncdaemon/local_rescan.py'
--- ubuntuone/syncdaemon/local_rescan.py 2011-08-10 15:03:17 +0000
+++ ubuntuone/syncdaemon/local_rescan.py 2011-08-22 15:52:23 +0000
@@ -2,7 +2,7 @@
2#2#
3# Author: Facundo Batista <facundo@canonical.com>3# Author: Facundo Batista <facundo@canonical.com>
4#4#
5# Copyright 2009 Canonical Ltd.5# Copyright 2009-2011 Canonical Ltd.
6#6#
7# This program is free software: you can redistribute it and/or modify it7# This program is free software: you can redistribute it and/or modify it
8# under the terms of the GNU General Public License version 3, as published8# under the terms of the GNU General Public License version 3, as published
@@ -56,6 +56,26 @@
56log_warning = functools.partial(lr_logger.log, logging.WARNING)56log_warning = functools.partial(lr_logger.log, logging.WARNING)
5757
5858
59def is_valid_name(path):
60 """Tell if the name is valid.
61
62 This checks for the bytes in the path to be UTF8 valid before let them
63 get into Syncdaemon.
64
65 There is a similar check in platform/linux/filesystem_notification.py; we
66 don't use that because this is more platform independant, will all go away
67 when put everything in unicode, and most importantly because don't want to
68 send invalid notifications and don't write in the invalid log for *every*
69 local rescan.
70 """
71 try:
72 path.decode("utf8")
73 except UnicodeDecodeError:
74 return False
75 else:
76 return True
77
78
59class LocalRescan(object):79class LocalRescan(object):
60 """Local re-scanner.80 """Local re-scanner.
6181
@@ -644,13 +664,22 @@
644 for something in dircontent:664 for something in dircontent:
645 fullname = os.path.join(dirpath, something)665 fullname = os.path.join(dirpath, something)
646 stat_result = get_stat(fullname)666 stat_result = get_stat(fullname)
647 if stat_result is None or is_link(fullname):667 if stat_result is None:
648 continue668 # gone between the listdir and now
649 elif not access(fullname):669 continue
670 if is_link(fullname):
671 log_info("Ignoring path as it's a symlink: %r", fullname)
672 continue
673 if not is_valid_name(fullname):
674 m = "Ignoring path because it's invalid (non utf8): %r"
675 log_info(m, fullname)
676 continue
677 if not access(fullname):
650 log_warning("Ignoring path as we don't have enough "678 log_warning("Ignoring path as we don't have enough "
651 "permissions to track it: %r", fullname)679 "permissions to track it: %r", fullname)
652 continue680 continue
653 elif stat.S_ISDIR(stat_result.st_mode):681
682 if stat.S_ISDIR(stat_result.st_mode):
654 dnames.append(something)683 dnames.append(something)
655 elif stat.S_ISREG(stat_result.st_mode):684 elif stat.S_ISREG(stat_result.st_mode):
656 fnames.append(something)685 fnames.append(something)

Subscribers

People subscribed via source and target branches