Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

host-mnt can be in different formats #20

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions docker_volume_watcher/call_debouncer.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ def __init__(self, callee, delay=0.1):
self._worker.setDaemon(True)
self._worker.start()


def __call__(self, *args, **kwargs):
self._calls.put((time.time(), CallArgs(*args, **kwargs)))

Expand All @@ -74,7 +73,7 @@ def _process_calls(self):

def _remove_outdated(self, submit_time):
while self._call_times:
cache_key, cache_time = next(iter(self._call_times.items())) # Pick first item
cache_key, cache_time = next(iter(self._call_times.items())) # Pick first item
if submit_time < cache_time:
break
self._call_times.pop(cache_key)
5 changes: 3 additions & 2 deletions docker_volume_watcher/cli.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
A tool to notify Docker contianers about changes in mounts on Windows.
A tool to notify Docker containers about changes in mounts on Windows.
"""

import argparse
Expand All @@ -15,7 +15,7 @@ def main():
"""

parser = argparse.ArgumentParser(
description='A tool to notify Docker contianers about changes in mounts on Windows.'
description='A tool to notify Docker containers about changes in mounts on Windows.'
)
parser.add_argument('container_pattern', metavar='CONTAINER_PATTERN', type=str, default='*',
nargs='?', help='pattern of container names to be notified (default: *)')
Expand Down Expand Up @@ -50,5 +50,6 @@ def main():

monitor.unwatch_all()


if __name__ == "__main__":
main()
11 changes: 7 additions & 4 deletions docker_volume_watcher/container_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@

def docker_bind_to_windows_path(path):
"""
Converts Hyper-V mount path to Windows path (e.g. [/host_mnt]/C/some-path -> C:/some-path).
Converts Hyper-V mount path to Windows path (e.g.
[/host_mnt]/C/some-path -> C:/some-path
[/run/desktop/mnt/host]/C/some-path -> C:/some-path
C:\\some-path -> C:\\some-path
).

Args:
path (str): Hyper-V mount path
Expand All @@ -24,8 +28,8 @@ def docker_bind_to_windows_path(path):
str: Converts Hyper-V mount path to Windows path (e.g. /C/some-path -> C:/some-path).

"""
expr = re.compile('^(?:/host_mnt)?/([a-zA-Z])/(.*)$')
match = re.match(expr, path)
expr = re.compile(r'^(?:/host_mnt/|/run/desktop/mnt/host/)?([a-zA-Z]):?[/\\](.*)$')
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not ^(?:/host_mnt|/run/desktop/mnt/host)?/([a-zA-Z]):?[/\\](.*)$?. Otherwise we will break compatibility with old versions (e.g. expression in your PR does not match /C/some-path)

match = expr.match(path)
if not match:
return None
return '%s:\\%s' % match.groups()
Expand All @@ -42,7 +46,6 @@ def __init__(self, container_name_pattern, host_dir_pattern, notifier_options=No
Args:
container_name_pattern (str): Container name pattern
host_dir_pattern (str): Host directory pattern
exclude_patterns (list): List of file name patterns for which changes should be ignored
notifier_options (NotifierOptions): options to be passed to each instance
of ContainerNotifier
"""
Expand Down