Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
fffonion committed Mar 27, 2019
2 parents 5a30109 + 79da83e commit c431b05
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 9 deletions.
10 changes: 8 additions & 2 deletions .travis.yml
@@ -1,14 +1,20 @@
os:
- linux
- windows

language: python
sudo: required
dist: xenial
python:
- 2.7
- 3.3
- 3.4
- 3.5
- 3.6
- 3.7

matrix:
include:
- python: 3.3
dist: trusty

install:
- python setup.py install
Expand Down
4 changes: 2 additions & 2 deletions xeHentai/const.py
Expand Up @@ -13,11 +13,11 @@
IRONPYTHON = sys.platform == 'cli'
EXEBUNDLE = getattr(sys, 'frozen', False)
LOCALE = locale.getdefaultlocale()[0]
CODEPAGE = locale.getdefaultlocale()[1]
CODEPAGE = locale.getdefaultlocale()[1] or 'ascii'
ANDROID = 'ANDROID_ARGUMENT' in os.environ

__version__ = 2.020
DEVELOPMENT = True
DEVELOPMENT = False

SCRIPT_NAME = "xeHentai"

Expand Down
23 changes: 20 additions & 3 deletions xeHentai/task.py
Expand Up @@ -10,6 +10,7 @@
import uuid
import shutil
import zipfile
import tempfile
from threading import RLock
from . import util
from .const import *
Expand Down Expand Up @@ -216,20 +217,36 @@ def save_file(self, imgurl, redirect_url, binary_iter):
# create a femp file first
# we don't need _f_lock because this will not be in a sequence
# and we can't do that otherwise we are breaking the multi threading
fn_tmp = os.path.join(fpath, ".%s.xeh" % self.get_fidpad(int(fid)))
fd_tmp, fn_tmp = tempfile.mkstemp(prefix="xehentai-")
os.close(fd_tmp)
try:
with open(fn_tmp, "wb") as f:
for binary in binary_iter():
if self._monitor._exit(None):
raise DownloadAbortedException()
f.write(binary)
except DownloadAbortedException as ex:
os.remove(fn_tmp)
try:
os.unlink(fn_tmp)
except:
pass
return

self._f_lock.acquire()
try:
os.rename(fn_tmp, fn)
try:
os.rename(fn_tmp, fn)
except WindowsError as ex:
# file is used by another process
# do a copy and delete, WindowsError[32]
if ex.errno == 13:
shutil.copy(fn_tmp, fn)
try:
os.unlink(fn_tmp)
except:
pass
else:
raise ex
self._cnt_lock.acquire()
self.meta['finished'] += 1
self._cnt_lock.release()
Expand Down
8 changes: 6 additions & 2 deletions xeHentai/util/__init__.py
Expand Up @@ -12,7 +12,7 @@
from ..const import *

if os.name == 'nt':
filename_filter = re.compile("[|:?\\/*'\"<>]|\.(?:$)")
filename_filter = re.compile("[|:?\\/*'\"<>]|\.+(?:$)")
else:# assume posix
filename_filter = re.compile("[\/:]")

Expand Down Expand Up @@ -79,4 +79,8 @@ def replc(match):
return htmlre.sub(replc, s)

def legalpath(s):
return filename_filter.sub(lambda x:"", s)
sanitized = filename_filter.sub(lambda x:"", s)
# windows doesn't like trailing while spaces
if os.name == 'nt':
sanitized = sanitized.rstrip()
return sanitized

0 comments on commit c431b05

Please sign in to comment.