|
@@ 64-98 (lines=35) @@
|
| 61 |
|
*/ |
| 62 |
|
class ExpectsFilesystem extends HostAwareModule |
| 63 |
|
{ |
| 64 |
|
public function hasFileWithPermissions($filename, $owner, $group, $mode) |
| 65 |
|
{ |
| 66 |
|
// shorthand |
| 67 |
|
$octMode = decoct($mode); |
| 68 |
|
|
| 69 |
|
// what are we doing? |
| 70 |
|
$log = Log::usingLog()->startAction("make sure file '{$filename}' exists on host '{$this->args[0]}' with permissions '{$octMode}' owned by '{$owner}:{$group}'"); |
| 71 |
|
|
| 72 |
|
// make sure we have valid host details |
| 73 |
|
$hostDetails = $this->getHostDetails(); |
| 74 |
|
|
| 75 |
|
// get the file details |
| 76 |
|
$details = Filesystem::fromHost($hostDetails->hostId)->getFileDetails($filename); |
| 77 |
|
|
| 78 |
|
// validate the details |
| 79 |
|
if ($details === null) { |
| 80 |
|
throw Exceptions::newExpectFailedException(__METHOD__, "'{$filename}' exists", "'{$filename}' does not exist"); |
| 81 |
|
} |
| 82 |
|
|
| 83 |
|
if ($details->type != 'file') { |
| 84 |
|
throw Exceptions::newExpectFailedException(__METHOD__, "'{$filename}' is a file", "'{$filename}' is type '{$details->type}'"); |
| 85 |
|
} |
| 86 |
|
|
| 87 |
|
if ($details->mode != $mode) { |
| 88 |
|
$theirOctMode = decoct($details->mode); |
| 89 |
|
throw Exceptions::newExpectFailedException(__METHOD__, "'{$filename}' has permissions '{$octMode}'", "'{$filename}' has permissions '{$theirOctMode}'"); |
| 90 |
|
} |
| 91 |
|
|
| 92 |
|
if ($details->user != $owner || $details->group != $group) { |
| 93 |
|
throw Exceptions::newExpectFailedException(__METHOD__, "'{$filename}' has ownership '{$owner}:{$group}'", "'{$filename}' has ownership '{$details->user}:{$details->group}'"); |
| 94 |
|
} |
| 95 |
|
|
| 96 |
|
// if we get here, then all is good |
| 97 |
|
$log->endAction(); |
| 98 |
|
} |
| 99 |
|
|
| 100 |
|
public function hasFolderWithPermissions($folder, $owner, $group, $mode) |
| 101 |
|
{ |
|
@@ 100-134 (lines=35) @@
|
| 97 |
|
$log->endAction(); |
| 98 |
|
} |
| 99 |
|
|
| 100 |
|
public function hasFolderWithPermissions($folder, $owner, $group, $mode) |
| 101 |
|
{ |
| 102 |
|
// shorthand |
| 103 |
|
$octMode = decoct($mode); |
| 104 |
|
|
| 105 |
|
// what are we doing? |
| 106 |
|
$log = Log::usingLog()->startAction("make sure folder '{$folder}' exists on host '{$this->args[0]}' with permissions '{$octMode}' owned by '{$owner}:{$group}'"); |
| 107 |
|
|
| 108 |
|
// make sure we have valid host details |
| 109 |
|
$hostDetails = $this->getHostDetails(); |
| 110 |
|
|
| 111 |
|
// get the file details |
| 112 |
|
$details = Filesystem::fromHost($hostDetails->hostId)->getFileDetails($folder); |
| 113 |
|
|
| 114 |
|
// validate the details |
| 115 |
|
if ($details === null) { |
| 116 |
|
throw Exceptions::newExpectFailedException(__METHOD__, "'{$folder}' exists", "'{$folder}' does not exist"); |
| 117 |
|
} |
| 118 |
|
|
| 119 |
|
if ($details->type != 'dir') { |
| 120 |
|
throw Exceptions::newExpectFailedException(__METHOD__, "'{$folder}' is a file", "'{$folder}' is type '{$details->type}'"); |
| 121 |
|
} |
| 122 |
|
|
| 123 |
|
if ($details->mode != $mode) { |
| 124 |
|
$theirOctMode = decoct($details->mode); |
| 125 |
|
throw Exceptions::newExpectFailedException(__METHOD__, "'{$folder}' has permissions '{$octMode}'", "'{$folder}' has permissions '{$theirOctMode}'"); |
| 126 |
|
} |
| 127 |
|
|
| 128 |
|
if ($details->user != $owner || $details->group != $group) { |
| 129 |
|
throw Exceptions::newExpectFailedException(__METHOD__, "'{$folder}' has ownership '{$owner}:{$group}'", "'{$folder}' has ownership '{$details->user}:{$details->group}'"); |
| 130 |
|
} |
| 131 |
|
|
| 132 |
|
// if we get here, then all is good |
| 133 |
|
$log->endAction(); |
| 134 |
|
} |
| 135 |
|
} |
| 136 |
|
|