Skip to content

Commit

Permalink
Use correct tmp dir when inside WSL
Browse files Browse the repository at this point in the history
  • Loading branch information
Shawn Dellysse committed Oct 15, 2019
1 parent 5be5b04 commit a54000d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
8 changes: 8 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[*.py]
indent_style = space
indent_size = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

1 change: 1 addition & 0 deletions newsfragments/1148.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
When runnning telepresence inside WSL, use a Docker-accessible directory as the TMP dir.
20 changes: 16 additions & 4 deletions telepresence/runner/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

import os
import platform
import select
import signal
import socket
Expand Down Expand Up @@ -70,14 +71,21 @@ def __init__(self, logfile_path: str, kubeinfo, verbose: bool) -> None:
self.quitting = False
self.ended = [] # type: typing.List[str]

self.is_wsl = False
if sys.platform.startswith("linux"):
self.platform = "linux"

# Detect if this platform is really linux-on-windows
if platform.uname().release.endswith("-Microsoft"):
self.is_wsl = True
elif sys.platform.startswith("darwin"):
self.platform = "darwin"
else:
# For untested platforms...
self.platform = sys.platform
self.output.write("uname: {}".format(platform.uname()))
self.output.write("Platform: {}".format(self.platform))
self.output.write("WSL: {}".format(self.is_wsl))

term_width = 99999
self.chatty = False
Expand Down Expand Up @@ -108,17 +116,21 @@ def __init__(self, logfile_path: str, kubeinfo, verbose: bool) -> None:

# Log some version info
self.output.write("Python {}".format(sys.version))
self.check_call(["uname", "-a"])

cache_dir = os.path.expanduser("~/.cache/telepresence")
os.makedirs(cache_dir, exist_ok=True)
self.cache = Cache.load(os.path.join(cache_dir, "cache.json"))
self.cache.invalidate(12 * 60 * 60)
self.add_cleanup("Save caches", self.cache.save)

# Docker for Mac only shares some folders; the default TMPDIR
# on OS X is not one of them, so make sure we use /tmp:
self.temp = Path(mkdtemp(prefix="tel-", dir="/tmp"))
# Docker for Mac doesn't share TMPDIR, so make sure we use /tmp
# Docker for Windows can't access /tmp, so use a directory it can
tmp_dir = "/tmp"
if self.is_wsl:
tmp_dir = "/c/temp"
if not os.path.exists(tmp_dir):
os.makedirs(tmp_dir)
self.temp = Path(mkdtemp(prefix="tel-", dir=tmp_dir))
(self.temp / "session_id.txt").write_text(self.session_id)
self.add_cleanup("Remove temporary directory", rmtree, str(self.temp))

Expand Down

0 comments on commit a54000d

Please sign in to comment.