Skip to content

Commit

Permalink
Revert Windows-specific optimization for mounting c drive
Browse files Browse the repository at this point in the history
- can break tests under some conditions
- see #573
  • Loading branch information
mrbean-bremen committed Dec 3, 2020
1 parent f1e5163 commit 807b6ff
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 22 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ The released versions correspond to PyPi releases.
## Version 4.4.0 (as yet unreleased)

### Fixes
* Reverted one Windows-specific optimization that can break tests under some
conditions (see [#573](../../issues/573))
* Setting `os` did not reset `os.sep` and related variables,
fixed null device name, added `os.pathsep` and missing `os.path` variables
(see [#572](../../issues/572))
Expand Down
27 changes: 7 additions & 20 deletions pyfakefs/fake_filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -1020,17 +1020,6 @@ def _starts_with_sep(self, path):
return (path.startswith(sep) or altsep is not None and
path.startswith(altsep))

def _add_c_drive(self):
"""Optimized version for the default Windows C drive.
For internal use only.
"""
if self.is_windows_fs:
self.last_dev += 1
self.mount_points['C:'] = {
'idev': self.last_dev, 'total_size': None, 'used_size': 0
}
self.root.get_entry('C:') .st_dev = self.last_dev

def add_mount_point(self, path, total_size=None):
"""Add a new mount point for a filesystem device.
The mount point gets a new unique device number.
Expand Down Expand Up @@ -2323,15 +2312,14 @@ def make_string_path(self, path):
fake_sep = matching_string(path, self.path_separator)
return path.replace(os_sep, fake_sep)

def create_dir(self, directory_path, perm_bits=PERM_DEF, check=True):
def create_dir(self, directory_path, perm_bits=PERM_DEF):
"""Create `directory_path`, and all the parent directories.
Helper method to set up your test faster.
Args:
directory_path: The full directory path to create.
perm_bits: The permission bits as set by `chmod`.
check: For internal use only.
Returns:
The newly created FakeDirectory object.
Expand All @@ -2340,11 +2328,10 @@ def create_dir(self, directory_path, perm_bits=PERM_DEF, check=True):
OSError: if the directory already exists.
"""
directory_path = self.make_string_path(directory_path)
if check:
directory_path = self.absnormpath(directory_path)
self._auto_mount_drive_if_needed(directory_path)
if self.exists(directory_path, check_link=True):
self.raise_os_error(errno.EEXIST, directory_path)
directory_path = self.absnormpath(directory_path)
self._auto_mount_drive_if_needed(directory_path)
if self.exists(directory_path, check_link=True):
self.raise_os_error(errno.EEXIST, directory_path)
path_components = self._path_components(directory_path)
current_dir = self.root

Expand All @@ -2357,10 +2344,10 @@ def create_dir(self, directory_path, perm_bits=PERM_DEF, check=True):
current_dir.add_entry(new_dir)
current_dir = new_dir
else:
if check and S_ISLNK(directory.st_mode):
if S_ISLNK(directory.st_mode):
directory = self.resolve(directory.contents)
current_dir = directory
if check and directory.st_mode & S_IFDIR != S_IFDIR:
if directory.st_mode & S_IFDIR != S_IFDIR:
self.raise_os_error(errno.ENOTDIR, current_dir.path)

# set the permission after creating the directories
Expand Down
3 changes: 1 addition & 2 deletions pyfakefs/fake_filesystem_unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -734,8 +734,7 @@ def setUp(self, doctester=None):

# the temp directory is assumed to exist at least in `tempfile1`,
# so we create it here for convenience
self.fs.create_dir(temp_dir, check=False)
self.fs._add_c_drive()
self.fs.create_dir(temp_dir)

def start_patching(self):
if not self._patching:
Expand Down

0 comments on commit 807b6ff

Please sign in to comment.