Spaces:
Running
Running
souliya_pps commited on
Commit ·
6232012
1
Parent(s): 09f04ee
fix: set writable HF_HOME so hf/xet CLI can run as www-data (permission denied on /root)
Browse files- app/Models/PushData.php +17 -2
app/Models/PushData.php
CHANGED
|
@@ -21,6 +21,21 @@ class PushData
|
|
| 21 |
return $dir;
|
| 22 |
}
|
| 23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
private function notificationsPath()
|
| 25 |
{
|
| 26 |
return $this->dataDir() . '/notifications.json';
|
|
@@ -186,7 +201,7 @@ class PushData
|
|
| 186 |
foreach ($uploads as $file => $target) {
|
| 187 |
$src = "$dataDir/$file";
|
| 188 |
if (!file_exists($src)) continue;
|
| 189 |
-
$cmd = '
|
| 190 |
$out = [];
|
| 191 |
$code = 0;
|
| 192 |
exec($cmd, $out, $code);
|
|
@@ -223,7 +238,7 @@ class PushData
|
|
| 223 |
|
| 224 |
$target = "$path/notifications.json";
|
| 225 |
$local = "$dataDir/notifications.json";
|
| 226 |
-
$cmd = '
|
| 227 |
$out = [];
|
| 228 |
$code = 0;
|
| 229 |
exec($cmd, $out, $code);
|
|
|
|
| 21 |
return $dir;
|
| 22 |
}
|
| 23 |
|
| 24 |
+
/**
|
| 25 |
+
* Build a writable HF home and wrap a command so the hf/xet CLI can cache
|
| 26 |
+
* its logs/data there. Apache runs as www-data (not root), so the default
|
| 27 |
+
* /root/.cache/huggingface is not writable and hf cp fails with
|
| 28 |
+
* "Permission denied (os error 13)".
|
| 29 |
+
*/
|
| 30 |
+
private function hfCommand($args)
|
| 31 |
+
{
|
| 32 |
+
$home = getenv('HF_HOME') ?: ($_ENV['HF_HOME'] ?? ($this->dataDir() . '/.hfhome'));
|
| 33 |
+
@mkdir($home, 0777, true);
|
| 34 |
+
return 'HF_HOME=' . escapeshellarg($home)
|
| 35 |
+
. ' HF_TOKEN=' . escapeshellarg(getenv('HF_TOKEN') ?: ($_ENV['HF_TOKEN'] ?? ''))
|
| 36 |
+
. ' hf ' . $args . ' 2>&1';
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
private function notificationsPath()
|
| 40 |
{
|
| 41 |
return $this->dataDir() . '/notifications.json';
|
|
|
|
| 201 |
foreach ($uploads as $file => $target) {
|
| 202 |
$src = "$dataDir/$file";
|
| 203 |
if (!file_exists($src)) continue;
|
| 204 |
+
$cmd = $this->hfCommand('cp ' . escapeshellarg($src) . ' hf://buckets/' . $bucket . '/' . escapeshellarg($target));
|
| 205 |
$out = [];
|
| 206 |
$code = 0;
|
| 207 |
exec($cmd, $out, $code);
|
|
|
|
| 238 |
|
| 239 |
$target = "$path/notifications.json";
|
| 240 |
$local = "$dataDir/notifications.json";
|
| 241 |
+
$cmd = $this->hfCommand('cp hf://buckets/' . $bucket . '/' . escapeshellarg($target) . ' ' . escapeshellarg($local));
|
| 242 |
$out = [];
|
| 243 |
$code = 0;
|
| 244 |
exec($cmd, $out, $code);
|