def test_file_delete(self): """Test the delete signal on a file.""" testfile = os.path.join(self.root_dir, "foo") open(testfile, "w").close() self.monitor.add_to_mute_filter("FS_FILE_DELETE", path=testfile) self.assertEqual(self._how_many_muted(), 1) yield self.monitor.add_watch(self.root_dir) # generate the event remove_file(testfile) reactor.callLater(self.timeout - 0.2, self.check_filter) test_result = yield self._deferred defer.returnValue(test_result)
def __delitem__(self, key): """ delitem backed by the file storage """ path = self.key_file(key) try: remove_file(self.key_file(key)) except OSError: raise KeyError(key) # also delete backup files for path in [path + '.old', path + '.new']: try: remove_file(path) except OSError: # ignore any OSError pass
def _check_and_create_dirs(self, path): """ check if the path isn't a file and in case it don't exists, creates it """ try: stat_result = stat_path(path) # is a regular file? if stat.S_ISREG(stat_result.st_mode): remove_file(path) make_dir(path, True) # else, the dir is already there except OSError, e: if e.errno == errno.ENOENT: # the file or dir don't exist make_dir(path, True) else: raise
def despair(message, fullname, also_children=False, also_remove=None): """Something went very bad with this node, converge!""" # if asked, remove metadata por children if also_children: log_debug("Removing metadata for %r children", fullname) # pylint: disable-msg=W0612 children = self.fsm.get_paths_starting_with(fullname, False) for path, is_dir in children: self.fsm.delete_metadata(path) # remove fullname after removing its children, # otherwise metadata removal may fail log_info(message, fullname) rename(fullname, fullname + ".u1conflict") self.fsm.delete_metadata(fullname) # if asked, remove also that file (if still exists) if also_remove is not None: try: log_info("Also remove %r", also_remove) remove_file(also_remove) except OSError, e: if e.errno != errno.ENOENT: raise
def test_path_exists_file_no(self): """The file is not there.""" remove_file(self.testfile) self.assertFalse(path_exists(self.testfile))
def test_remove_file(self): """Test the remove file.""" remove_file(self.testfile) self.assertFalse(path_exists(self.testfile))
def test_path_file_exist_no(self): """Test that the file doesn't exist.""" remove_file(self.testfile) self.assertFalse(path_exists(self.testfile))
def delete(self): """Delete this file and the hint if exists.""" self.close() remove_file(self.filename) if self.has_hint: remove_file(self.hint_filename)