mirror of
https://github.com/Kozea/Radicale.git
synced 2025-08-01 18:18:31 +00:00
Use sys.platform instead of os.name
mypy only recognizes sys.platform
This commit is contained in:
parent
523960bc9f
commit
0221fc357b
7 changed files with 21 additions and 33 deletions
|
@ -17,6 +17,7 @@
|
|||
# along with Radicale. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import os
|
||||
import sys
|
||||
from tempfile import TemporaryDirectory
|
||||
from typing import IO, AnyStr, ClassVar, Iterator, Optional, Type
|
||||
|
||||
|
@ -93,7 +94,7 @@ class StorageBase(storage.BaseStorage):
|
|||
"""
|
||||
if not self._filesystem_fsync:
|
||||
return
|
||||
if os.name == "posix":
|
||||
if sys.platform != "win32":
|
||||
try:
|
||||
fd = os.open(path, 0)
|
||||
try:
|
||||
|
|
|
@ -68,11 +68,11 @@ class StoragePartLock(StorageBase):
|
|||
# from sending SIGINT etc.
|
||||
preexec_fn = None
|
||||
creationflags = 0
|
||||
if os.name == "posix":
|
||||
if sys.platform == "win32":
|
||||
creationflags |= subprocess.CREATE_NEW_PROCESS_GROUP
|
||||
else:
|
||||
# Process group is also used to identify child processes
|
||||
preexec_fn = os.setpgrp
|
||||
elif sys.platform == "win32":
|
||||
creationflags |= subprocess.CREATE_NEW_PROCESS_GROUP
|
||||
command = self._hook % {
|
||||
"user": shlex.quote(user or "Anonymous")}
|
||||
logger.debug("Running storage hook")
|
||||
|
@ -89,7 +89,7 @@ class StoragePartLock(StorageBase):
|
|||
p.wait()
|
||||
raise
|
||||
finally:
|
||||
if os.name == "posix":
|
||||
if sys.platform != "win32":
|
||||
# Kill remaining children identified by process group
|
||||
with contextlib.suppress(OSError):
|
||||
os.killpg(p.pid, signal.SIGKILL)
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
# You should have received a copy of the GNU General Public License
|
||||
# along with Radicale. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import errno
|
||||
import os
|
||||
import pickle
|
||||
import sys
|
||||
|
@ -76,15 +77,12 @@ class CollectionPartUpload(CollectionPartGet, CollectionPartCache,
|
|||
raise ValueError(
|
||||
"Failed to store item %r in temporary collection %r: %s" %
|
||||
(uid, self.path, e)) from e
|
||||
href_candidate_funtions = []
|
||||
if os.name == "posix" or sys.platform == "win32":
|
||||
href_candidate_funtions.append(
|
||||
lambda: uid if uid.lower().endswith(suffix.lower())
|
||||
else uid + suffix)
|
||||
href_candidate_funtions.extend((
|
||||
href_candidate_funtions = [
|
||||
lambda: uid if uid.lower().endswith(suffix.lower())
|
||||
else uid + suffix,
|
||||
lambda: radicale_item.get_etag(uid).strip('"') + suffix,
|
||||
lambda: radicale_item.find_available_uid(hrefs.__contains__,
|
||||
suffix)))
|
||||
lambda: radicale_item.find_available_uid(
|
||||
hrefs.__contains__, suffix)]
|
||||
href = f = None
|
||||
while href_candidate_funtions:
|
||||
href = href_candidate_funtions.pop(0)()
|
||||
|
@ -101,7 +99,8 @@ class CollectionPartUpload(CollectionPartGet, CollectionPartCache,
|
|||
break
|
||||
except OSError as e:
|
||||
if href_candidate_funtions and (
|
||||
os.name == "posix" and e.errno == 22 or
|
||||
sys.platform != "win32" and
|
||||
e.errno == errno.EINVAL or
|
||||
sys.platform == "win32" and e.errno == 123):
|
||||
continue
|
||||
raise
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue