Commit 41efb9b7 by willmcgugan@gmail.com

Test fixes

parent ea7f6b43
Copyright (c) 2009-2012, Will McGugan <will@willmcgugan.com> and contributors.
Copyright (c) 2009-2014, Will McGugan <will@willmcgugan.com> and contributors.
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
......
......@@ -15,7 +15,7 @@ implementations of this interface such as:
"""
__version__ = "0.4.1"
__version__ = "0.5.0-dev"
__author__ = "Will McGugan (will@willmcgugan.com)"
# provide these by default so people can use 'fs.path.basename' etc.
......
......@@ -266,6 +266,10 @@ def convert_os_errors(func):
raise OperationFailedError(opname,details=e),None,tb
if e.errno == errno.ENOENT:
raise ResourceNotFoundError(path,opname=opname,details=e),None,tb
if e.errno == errno.EFAULT:
# This can happen when listdir a directory that is deleted by another thread
# Best to interpret it as a resource not found
raise ResourceNotFoundError(path,opname=opname,details=e),None,tb
if e.errno == errno.ESRCH:
raise ResourceNotFoundError(path,opname=opname,details=e),None,tb
if e.errno == errno.ENOTEMPTY:
......
......@@ -21,6 +21,7 @@ import errno
import datetime
import platform
import io
import shutil
from fs.base import *
from fs.path import *
......@@ -246,7 +247,9 @@ class OSFS(OSFSXAttrMixin, OSFSWatchMixin, FS):
@convert_os_errors
def listdir(self, path="./", wildcard=None, full=False, absolute=False, dirs_only=False, files_only=False):
_decode_path = self._decode_path
paths = [_decode_path(p) for p in os.listdir(self.getsyspath(path))]
sys_path = self.getsyspath(path)
listing = os.listdir(sys_path)
paths = [_decode_path(p) for p in listing]
return self._listdir_helper(path, paths, wildcard, full, absolute, dirs_only, files_only)
@convert_os_errors
......@@ -283,22 +286,15 @@ class OSFS(OSFSXAttrMixin, OSFSWatchMixin, FS):
@convert_os_errors
def removedir(self, path, recursive=False, force=False):
sys_path = self.getsyspath(path)
if force:
for path2 in self.listdir(path, absolute=True, files_only=True):
try:
self.remove(path2)
except ResourceNotFoundError:
pass
for path2 in self.listdir(path, absolute=True, dirs_only=True):
try:
self.removedir(path2, force=True)
except ResourceNotFoundError:
pass
# Don't remove the root directory of this FS
if path in ('', '/'):
raise RemoveRootError(path)
os.rmdir(sys_path)
sys_path = self.getsyspath(path)
if force:
# shutil implementation handles concurrency better
shutil.rmtree(sys_path, ignore_errors=True)
else:
os.rmdir(sys_path)
# Using os.removedirs() for this can result in dirs being
# removed outside the root of this FS, so we recurse manually.
if recursive:
......
......@@ -137,7 +137,6 @@ class FSTestCases(object):
f.close()
def test_createfile(self):
"""Test createfile"""
test = b('now with content')
self.fs.createfile("test.txt")
self.assert_(self.fs.exists("test.txt"))
......@@ -396,8 +395,8 @@ class FSTestCases(object):
alpha = u"\N{GREEK SMALL LETTER ALPHA}"
beta = u"\N{GREEK SMALL LETTER BETA}"
self.fs.makedir(alpha)
self.fs.setcontents(alpha+"/a", b(''))
self.fs.setcontents(alpha+"/"+beta, b(''))
self.fs.setcontents(alpha + "/a", b(''))
self.fs.setcontents(alpha + "/" + beta, b(''))
self.assertTrue(self.check(alpha))
self.assertEquals(sorted(self.fs.listdir(alpha)), ["a", beta])
......
......@@ -315,7 +315,7 @@ class WatchableFS(WatchableFSMixin,WrapFS):
def setcontents(self, path, data=b'', encoding=None, errors=None, chunk_size=64*1024):
existed = self.wrapped_fs.isfile(path)
ret = super(WatchableFS, self).setcontents(path, data, chunk_size=chunk_size)
ret = super(WatchableFS, self).setcontents(path, data=data, encoding=encoding, errors=errors, chunk_size=chunk_size)
if not existed:
self.notify_watchers(CREATED, path)
self.notify_watchers(ACCESSED, path)
......@@ -325,7 +325,7 @@ class WatchableFS(WatchableFSMixin,WrapFS):
def createfile(self, path, wipe=False):
existed = self.wrapped_fs.isfile(path)
ret = super(WatchableFS, self).createfile(path, wipe=False)
ret = super(WatchableFS, self).createfile(path, wipe=wipe)
if not existed:
self.notify_watchers(CREATED,path)
self.notify_watchers(ACCESSED,path)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment