Skip to content

Commit

Permalink
Dropping directory creation in install:
Browse files Browse the repository at this point in the history
SHFileOperation seems coping with that alright - shutil blows, patched
that - see:

https://stackoverflow.com/a/46014620/281545

I dropped the `if srcFull.exists()` it should always, otherwise let it
blow.

Under #241, appropriately named __copyOrMove is an abomination, plus
we need to move all Path operations into env and write tests.
Maybe also related to #315 ?
  • Loading branch information
Utumno committed Sep 6, 2017
1 parent 2412203 commit aa11399
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 19 deletions.
23 changes: 9 additions & 14 deletions Mopy/bash/bosh/bain.py
Expand Up @@ -986,24 +986,19 @@ def _fs_install(self, dest_src, srcDirJoin, progress,
data_sizeCrcDate_update = bolt.LowerDict()
data_sizeCrc = self.data_sizeCrc
mods, inis = set(), set()
created_dirs = set()
srcs, dests = [], []
for dest, src in dest_src.iteritems():
size,crc = data_sizeCrc[dest]
srcFull = srcDirJoin(src)
if srcFull.exists(): ## drop this syscall !
stageFull = bass.dirs['mods'].join(norm_ghostGet(dest, dest))
if stageFull.head not in created_dirs: ## FIXME(ut): needed ? In both env shell and non shell paths?
stageFull.head.makedirs()
created_dirs.add(stageFull.head)
if bass.reModExt.search(srcFull.s):
mods.add(srcFull.tail)
elif InstallersData._is_ini_tweak(dest):
inis.add(srcFull.tail)
data_sizeCrcDate_update[dest] = (size, crc, -1) ##: HACK we must try avoid stat'ing the mtime
srcs.append(srcFull)
dests.append(stageFull)
subprogressPlus()
destFull = bass.dirs['mods'].join(norm_ghostGet(dest, dest))
if bass.reModExt.search(srcFull.s):
mods.add(srcFull.tail)
elif InstallersData._is_ini_tweak(dest):
inis.add(srcFull.tail)
data_sizeCrcDate_update[dest] = (size, crc, -1) ##: HACK we must try avoid stat'ing the mtime
srcs.append(srcFull)
dests.append(destFull)
subprogressPlus()
#--Now Move
try:
if data_sizeCrcDate_update:
Expand Down
21 changes: 16 additions & 5 deletions Mopy/bash/env.py
Expand Up @@ -24,11 +24,13 @@

"""WIP module to encapsulate environment access - currently OS dependent stuff.
"""
import errno
import os as _os
import re as _re
import shutil as _shutil
import stat
import struct
import shutil as _shutil

from bolt import GPath, deprint, Path, decode
from exception import BoltError, CancelError, SkipError, AccessDeniedError, \
DirectoryFileCollisionError, InvalidPathsError, FileOperationError, \
Expand Down Expand Up @@ -434,15 +436,24 @@ def __copyOrMove(operation, source, target, renameOnCollision, parent):
if not dest_dir.isdir():
raise DirectoryFileCollisionError(fileFrom, dest_dir)
# dir exists at target, copy contents individually/recursively
srcs, dests = [], []
for content in _os.listdir(fileFrom.s):
__copyOrMove(operation, [fileFrom.join(content)],
[dest_dir], renameOnCollision, parent)
srcs.append(fileFrom.join(content))
dests.append(dest_dir)
__copyOrMove(operation, srcs, dests, renameOnCollision, parent)
else: # dir doesn't exist at the target, copy it
doIt(fileFrom.s, fileTo.s)
# copy the file, overwrite as needed
elif fileFrom.isfile(): # or os.path.islink(file):
# move may not work if the target exists, copy instead...
_shutil.copy2(fileFrom.s, fileTo.s) # ...and overwrite as needed
# move may not work if the target exists, copy instead and
# overwrite as needed
try:
_shutil.copy2(fileFrom.s, fileTo.s)
except IOError as e:
if e.errno != errno.ENOENT: raise
# probably directory path does not exist, create it.
fileTo.head.makedirs()
_shutil.copy2(fileFrom.s, fileTo.s)
if operation == FO_MOVE: fileFrom.remove() # then remove original
return {} ##: the renames map ?

Expand Down

0 comments on commit aa11399

Please sign in to comment.