1
0
Fork 0
mirror of https://github.com/borgbackup/borg.git synced 2025-03-19 02:15:49 +00:00

refactor/move hostname/fqdn related funcs, see #3471

- move stuff to platform.base (should be platform independent according
  to the docs).
- bump platform API version
- parseformat: import fqdn from platform instead of recomputing it

This is not yet fixing #3471, just a preparation for it.

(cherry picked from commit 5e4df7782b)
This commit is contained in:
Thomas Waldmann 2017-12-24 04:12:02 +01:00
parent 128ed2da47
commit f00e9de492
7 changed files with 26 additions and 32 deletions

View file

@ -139,7 +139,7 @@ def check_extension_modules():
raise ExtensionModuleError
if borg.crypto.low_level.API_VERSION != '1.1_02':
raise ExtensionModuleError
if platform.API_VERSION != platform.OS_API_VERSION != '1.1_02':
if platform.API_VERSION != platform.OS_API_VERSION != '1.1_03':
raise ExtensionModuleError
if item.API_VERSION != '1.1_02':
raise ExtensionModuleError
@ -664,8 +664,8 @@ def format_line(format, data):
def replace_placeholders(text):
"""Replace placeholders in text with their values."""
from .platform import fqdn
current_time = datetime.now()
fqdn = socket.getfqdn()
data = {
'pid': os.getpid(),
'fqdn': fqdn,

View file

@ -10,12 +10,12 @@ from .base import acl_get, acl_set
from .base import set_flags, get_flags
from .base import SaveFile, SyncFile, sync_dir, fdatasync, safe_fadvise
from .base import swidth, API_VERSION
from .base import process_alive, get_process_id, local_pid_alive
from .base import process_alive, get_process_id, local_pid_alive, fqdn, hostname, hostid
OS_API_VERSION = API_VERSION
if not sys.platform.startswith(('win32', )):
from .posix import process_alive, get_process_id, local_pid_alive
from .posix import process_alive, local_pid_alive
if sys.platform.startswith('linux'): # pragma: linux only
from .linux import API_VERSION as OS_API_VERSION

View file

@ -1,5 +1,7 @@
import errno
import os
import socket
import uuid
from borg.helpers import truncate_and_unlink
@ -15,7 +17,7 @@ platform API: that way platform APIs provided by the platform-specific support m
are correctly composed into the base functionality.
"""
API_VERSION = '1.1_02'
API_VERSION = '1.1_03'
fdatasync = getattr(os, 'fdatasync', os.fsync)
@ -183,12 +185,23 @@ def swidth(s):
return len(s)
# for performance reasons, only determine hostname / fqdn / hostid once.
# XXX this sometimes requires live internet access for issuing a DNS query in the background.
hostname = socket.gethostname()
fqdn = socket.getfqdn()
hostid = '%s@%s' % (fqdn, uuid.getnode())
def get_process_id():
"""
Return identification tuple (hostname, pid, thread_id) for 'us'. If this is a FUSE process, then the PID will be
that of the parent, not the forked FUSE child.
Return identification tuple (hostname, pid, thread_id) for 'us'.
This always returns the current pid, which might be different from before, e.g. if daemonize() was used.
Note: Currently thread_id is *always* zero.
"""
raise NotImplementedError
thread_id = 0
pid = os.getpid()
return hostid, pid, thread_id
def process_alive(host, pid, thread):

View file

@ -4,7 +4,7 @@ from ..helpers import user2uid, group2gid
from ..helpers import safe_decode, safe_encode
from .posix import swidth
API_VERSION = '1.1_02'
API_VERSION = '1.1_03'
cdef extern from "sys/acl.h":
ctypedef struct _acl_t:

View file

@ -4,7 +4,7 @@ from ..helpers import posix_acl_use_stored_uid_gid
from ..helpers import safe_encode, safe_decode
from .posix import swidth
API_VERSION = '1.1_02'
API_VERSION = '1.1_03'
cdef extern from "errno.h":
int errno

View file

@ -13,7 +13,7 @@ from .posix import swidth
from libc cimport errno
from libc.stdint cimport int64_t
API_VERSION = '1.1_02'
API_VERSION = '1.1_03'
cdef extern from "sys/types.h":
int ACL_TYPE_ACCESS

View file

@ -1,8 +1,5 @@
import errno
import os
import uuid
import socket
import subprocess
cdef extern from "wchar.h":
@ -18,23 +15,6 @@ def swidth(s):
return str_len
# for performance reasons, only determine the hostname once.
# XXX this sometimes requires live internet access for issuing a DNS query in the background.
_hostname = '%s@%s' % (socket.getfqdn(), uuid.getnode())
def get_process_id():
"""
Return identification tuple (hostname, pid, thread_id) for 'us'.
This always returns the current pid, which might be different from before, e.g. if daemonize() was used.
Note: Currently thread_id is *always* zero.
"""
thread_id = 0
pid = os.getpid()
return _hostname, pid, thread_id
def process_alive(host, pid, thread):
"""
Check if the (host, pid, thread_id) combination corresponds to a potentially alive process.
@ -43,8 +23,9 @@ def process_alive(host, pid, thread):
returns always True, since there is no real way to check.
"""
from . import local_pid_alive
from . import hostid
if host != _hostname:
if host != hostid:
return True
if thread != 0: