Skip to content

Commit

Permalink
Change the mounted directory from host to site-name.env
Browse files Browse the repository at this point in the history
  - Add message indicating the mounted directory in README.md
  - Check if the mounted directory exists before attempting to unmount
  - Remove the mounted directory after unmounting
  - Add composer.lock to .gitignore
  • Loading branch information
uberhacker committed Jan 22, 2017
1 parent 110d0ea commit 3cfb3bf
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
composer.lock
vendor
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

Terminus plugin to mount Pantheon sites.

The site environment will be mounted in `/tmp/site-name.dev`.

## Examples:
Mount the site environment awesome-site.dev.
```
Expand Down
25 changes: 17 additions & 8 deletions src/Commands/SiteMountCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ public function mount($site_env = '')
}

// Determine connection information.
list($site, $env) = $this->getSiteEnv($site_env);
list(, $env) = $this->getSiteEnv($site_env);
$connection_info = $env->sftpConnectionInfo();
$user = $connection_info['username'];
$host = $connection_info['host'];
$port = $connection_info['port'];

// Determine the mount location.
$windows = (php_uname('s') == 'Windows NT');
$mount = $windows ? "\\Temp\\{$host}" : "/tmp/{$host}";
$mount = $windows ? "\\Temp\\{$site_env}" : "/tmp/{$site_env}";

// Create the mount directory if it doesn't exist.
$command = "if [ ! -d {$mount} ]; then mkdir {$mount}; fi";
Expand Down Expand Up @@ -89,14 +89,16 @@ public function unmount($site_env = '')
throw new TerminusNotFoundException($message);
}

// Determine connection information.
list($site, $env) = $this->getSiteEnv($site_env);
$connection_info = $env->sftpConnectionInfo();
$host = $connection_info['host'];

// Determine the mount location.
$windows = (php_uname('s') == 'Windows NT');
$mount = $windows ? "\\Temp\\{$host}" : "/tmp/{$host}";
$mount = $windows ? "\\Temp\\{$site_env}" : "/tmp/{$site_env}";

// Check if the directory exists.
if (!file_exists($mount)) {
$message = "Site environment {$site_env} not mounted.";
$this->log()->notice($message);
return;
}

// Cannot unmount inside a mounted directory.
exec('pwd', $directory);
Expand All @@ -112,6 +114,13 @@ public function unmount($site_env = '')
foreach ($messages as $message) {
$this->log()->notice($message);
}

// Remove mount directory.
$command = "rmdir {$mount}";
exec($command, $messages);
foreach ($messages as $message) {
$this->log()->notice($message);
}
}

/**
Expand Down

0 comments on commit 3cfb3bf

Please sign in to comment.