Also check folder permissions for the EEPROM scripts.
This commit is contained in:
parent
9d70505ad8
commit
55dc011df6
8 changed files with 144 additions and 117 deletions
2
VERSION
2
VERSION
|
@ -1 +1 @@
|
||||||
20250327.1
|
20250403
|
||||||
|
|
|
@ -7,8 +7,8 @@ use Misuzu\Storage\HashHelpers;
|
||||||
|
|
||||||
class FilesStorage {
|
class FilesStorage {
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private string $localPath,
|
public private(set) string $localPath,
|
||||||
private string $remotePath,
|
public private(set) string $remotePath,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
public static function stringifyHash(FileInfo|string $infoOrHash): string {
|
public static function stringifyHash(FileInfo|string $infoOrHash): string {
|
||||||
|
|
214
tools/cron
214
tools/cron
|
@ -250,123 +250,127 @@ try {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
msz_sched_task_func('Removing stale entries from storage pools...', false, function() use ($msz) {
|
if(!empty($msz->storageCtx->filesCtx->storage->localPath)
|
||||||
$pools = [];
|
&& is_dir($msz->storageCtx->filesCtx->storage->localPath)
|
||||||
$getPool = fn($ruleRaw) => array_key_exists($ruleRaw->poolId, $pools) ? $pools[$ruleRaw->poolId] : (
|
&& fileowner($msz->storageCtx->filesCtx->storage->localPath) === posix_getuid()) {
|
||||||
$pools[$ruleRaw->poolId] = $msz->storageCtx->poolsCtx->pools->getPool($ruleRaw->poolId)
|
msz_sched_task_func('Removing stale entries from storage pools...', false, function() use ($msz) {
|
||||||
);
|
$pools = [];
|
||||||
|
$getPool = fn($ruleRaw) => array_key_exists($ruleRaw->poolId, $pools) ? $pools[$ruleRaw->poolId] : (
|
||||||
|
$pools[$ruleRaw->poolId] = $msz->storageCtx->poolsCtx->pools->getPool($ruleRaw->poolId)
|
||||||
|
);
|
||||||
|
|
||||||
// Run cleanup adjacent tasks first
|
// Run cleanup adjacent tasks first
|
||||||
$rules = $msz->storageCtx->poolsCtx->pools->getPoolRules(types: ['remove_stale', 'scan_forum']);
|
$rules = $msz->storageCtx->poolsCtx->pools->getPoolRules(types: ['remove_stale', 'scan_forum']);
|
||||||
foreach($rules as $ruleRaw) {
|
foreach($rules as $ruleRaw) {
|
||||||
$poolInfo = $getPool($ruleRaw);
|
$poolInfo = $getPool($ruleRaw);
|
||||||
$rule = $msz->storageCtx->poolsCtx->rules->create($ruleRaw);
|
$rule = $msz->storageCtx->poolsCtx->rules->create($ruleRaw);
|
||||||
|
|
||||||
if($rule instanceof RemoveStaleRule) {
|
if($rule instanceof RemoveStaleRule) {
|
||||||
printf('Removing stale entries for pool #%d...%s', $poolInfo->id, PHP_EOL);
|
printf('Removing stale entries for pool #%d...%s', $poolInfo->id, PHP_EOL);
|
||||||
$msz->storageCtx->uploadsCtx->uploads->deleteStaleUploads(
|
$msz->storageCtx->uploadsCtx->uploads->deleteStaleUploads(
|
||||||
$poolInfo,
|
$poolInfo,
|
||||||
$rule->inactiveForSeconds,
|
$rule->inactiveForSeconds,
|
||||||
$rule->ignoreUploadIds
|
$rule->ignoreUploadIds
|
||||||
);
|
);
|
||||||
} elseif($rule instanceof ScanForumRule) {
|
} elseif($rule instanceof ScanForumRule) {
|
||||||
//var_dump('scan_forum', $rule);
|
//var_dump('scan_forum', $rule);
|
||||||
// necessary stuff for this doesn't exist yet so this can remain a no-op
|
// necessary stuff for this doesn't exist yet so this can remain a no-op
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
});
|
|
||||||
|
|
||||||
msz_sched_task_func('Purging denylisted files...', true, function() use ($msz) {
|
msz_sched_task_func('Purging denylisted files...', true, function() use ($msz) {
|
||||||
$fileInfos = $msz->storageCtx->filesCtx->data->getFiles(denied: true);
|
$fileInfos = $msz->storageCtx->filesCtx->data->getFiles(denied: true);
|
||||||
foreach($fileInfos as $fileInfo) {
|
foreach($fileInfos as $fileInfo) {
|
||||||
printf('Deleting file #%d...%s', $fileInfo->id, PHP_EOL);
|
printf('Deleting file #%d...%s', $fileInfo->id, PHP_EOL);
|
||||||
$msz->storageCtx->filesCtx->deleteFile($fileInfo);
|
$msz->storageCtx->filesCtx->deleteFile($fileInfo);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
msz_sched_task_func('Purging orphaned files...', true, function() use ($msz) {
|
msz_sched_task_func('Purging orphaned files...', true, function() use ($msz) {
|
||||||
$fileInfos = $msz->storageCtx->filesCtx->data->getFiles(orphaned: true);
|
$fileInfos = $msz->storageCtx->filesCtx->data->getFiles(orphaned: true);
|
||||||
foreach($fileInfos as $fileInfo) {
|
foreach($fileInfos as $fileInfo) {
|
||||||
printf('Deleting file #%d...%s', $fileInfo->id, PHP_EOL);
|
printf('Deleting file #%d...%s', $fileInfo->id, PHP_EOL);
|
||||||
$msz->storageCtx->filesCtx->deleteFile($fileInfo);
|
$msz->storageCtx->filesCtx->deleteFile($fileInfo);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
msz_sched_task_func('Ensuring alternate variants exist...', true, function() use ($msz) {
|
msz_sched_task_func('Ensuring alternate variants exist...', true, function() use ($msz) {
|
||||||
$pools = [];
|
$pools = [];
|
||||||
$getPool = fn($ruleRaw) => array_key_exists($ruleRaw->poolId, $pools) ? $pools[$ruleRaw->poolId] : (
|
$getPool = fn($ruleRaw) => array_key_exists($ruleRaw->poolId, $pools) ? $pools[$ruleRaw->poolId] : (
|
||||||
$pools[$ruleRaw->poolId] = $msz->storageCtx->poolsCtx->pools->getPool($ruleRaw->poolId)
|
$pools[$ruleRaw->poolId] = $msz->storageCtx->poolsCtx->pools->getPool($ruleRaw->poolId)
|
||||||
);
|
);
|
||||||
|
|
||||||
$rules = $msz->storageCtx->poolsCtx->pools->getPoolRules(types: ['ensure_variant']);
|
$rules = $msz->storageCtx->poolsCtx->pools->getPoolRules(types: ['ensure_variant']);
|
||||||
foreach($rules as $ruleRaw) {
|
foreach($rules as $ruleRaw) {
|
||||||
$poolInfo = $getPool($ruleRaw);
|
$poolInfo = $getPool($ruleRaw);
|
||||||
$rule = $msz->storageCtx->poolsCtx->rules->create($ruleRaw);
|
$rule = $msz->storageCtx->poolsCtx->rules->create($ruleRaw);
|
||||||
|
|
||||||
if($rule instanceof EnsureVariantRule) {
|
if($rule instanceof EnsureVariantRule) {
|
||||||
if(!$rule->onCron)
|
if(!$rule->onCron)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
$createVariant = null; // ensure this wasn't previously assigned
|
$createVariant = null; // ensure this wasn't previously assigned
|
||||||
if($rule->params instanceof EnsureVariantRuleThumb) {
|
if($rule->params instanceof EnsureVariantRuleThumb) {
|
||||||
$createVariant = function(
|
$createVariant = function(
|
||||||
FilesContext $filesCtx,
|
FilesContext $filesCtx,
|
||||||
UploadsContext $uploadsCtx,
|
UploadsContext $uploadsCtx,
|
||||||
PoolInfo $poolInfo,
|
PoolInfo $poolInfo,
|
||||||
EnsureVariantRule $rule,
|
EnsureVariantRule $rule,
|
||||||
EnsureVariantRuleThumb $ruleInfo,
|
EnsureVariantRuleThumb $ruleInfo,
|
||||||
FileInfo $originalInfo,
|
FileInfo $originalInfo,
|
||||||
UploadInfo $uploadInfo
|
UploadInfo $uploadInfo
|
||||||
) {
|
) {
|
||||||
$uploadsCtx->uploads->createUploadVariant(
|
$uploadsCtx->uploads->createUploadVariant(
|
||||||
$uploadInfo,
|
$uploadInfo,
|
||||||
$rule->variant,
|
$rule->variant,
|
||||||
$filesCtx->createThumbnailFromRule(
|
$filesCtx->createThumbnailFromRule(
|
||||||
$originalInfo,
|
$originalInfo,
|
||||||
$ruleInfo
|
$ruleInfo
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
}
|
|
||||||
|
|
||||||
if(!isset($createVariant) || !is_callable($createVariant)) {
|
|
||||||
printf('!!! Could not create a constructor for "%s" variants for pool #%d !!! Skipping for now...%s', $rule->variant, $poolInfo->id, PHP_EOL);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
printf('Ensuring existence of "%s" variants for pool #%d...%s', $rule->variant, $poolInfo->id, PHP_EOL);
|
|
||||||
|
|
||||||
$uploads = $msz->storageCtx->uploadsCtx->uploads->getUploads(
|
|
||||||
poolInfo: $poolInfo,
|
|
||||||
variant: $rule->variant,
|
|
||||||
variantExists: false
|
|
||||||
);
|
|
||||||
|
|
||||||
$processed = 0;
|
|
||||||
foreach($uploads as $uploadInfo)
|
|
||||||
try {
|
|
||||||
$createVariant(
|
|
||||||
$msz->storageCtx->filesCtx,
|
|
||||||
$msz->storageCtx->uploadsCtx,
|
|
||||||
$poolInfo,
|
|
||||||
$rule,
|
|
||||||
$rule->params,
|
|
||||||
$msz->storageCtx->filesCtx->data->getFile(
|
|
||||||
$msz->storageCtx->uploadsCtx->uploads->getUploadVariant($uploadInfo, '')->fileId
|
|
||||||
),
|
|
||||||
$uploadInfo
|
|
||||||
);
|
|
||||||
} catch(Exception $ex) {
|
|
||||||
printf('Exception thrown while processing "%s" variant for upload #%d in pool #%d:%s', $rule->variant, $uploadInfo->id, $poolInfo->id, PHP_EOL);
|
|
||||||
printf('%s%s', $ex->getMessage(), PHP_EOL);
|
|
||||||
} finally {
|
|
||||||
++$processed;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
printf('Processed %d records!%s%s', $processed, PHP_EOL);
|
if(!isset($createVariant) || !is_callable($createVariant)) {
|
||||||
|
printf('!!! Could not create a constructor for "%s" variants for pool #%d !!! Skipping for now...%s', $rule->variant, $poolInfo->id, PHP_EOL);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf('Ensuring existence of "%s" variants for pool #%d...%s', $rule->variant, $poolInfo->id, PHP_EOL);
|
||||||
|
|
||||||
|
$uploads = $msz->storageCtx->uploadsCtx->uploads->getUploads(
|
||||||
|
poolInfo: $poolInfo,
|
||||||
|
variant: $rule->variant,
|
||||||
|
variantExists: false
|
||||||
|
);
|
||||||
|
|
||||||
|
$processed = 0;
|
||||||
|
foreach($uploads as $uploadInfo)
|
||||||
|
try {
|
||||||
|
$createVariant(
|
||||||
|
$msz->storageCtx->filesCtx,
|
||||||
|
$msz->storageCtx->uploadsCtx,
|
||||||
|
$poolInfo,
|
||||||
|
$rule,
|
||||||
|
$rule->params,
|
||||||
|
$msz->storageCtx->filesCtx->data->getFile(
|
||||||
|
$msz->storageCtx->uploadsCtx->uploads->getUploadVariant($uploadInfo, '')->fileId
|
||||||
|
),
|
||||||
|
$uploadInfo
|
||||||
|
);
|
||||||
|
} catch(Exception $ex) {
|
||||||
|
printf('Exception thrown while processing "%s" variant for upload #%d in pool #%d:%s', $rule->variant, $uploadInfo->id, $poolInfo->id, PHP_EOL);
|
||||||
|
printf('%s%s', $ex->getMessage(), PHP_EOL);
|
||||||
|
} finally {
|
||||||
|
++$processed;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf('Processed %d records!%s%s', $processed, PHP_EOL);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
});
|
}
|
||||||
|
|
||||||
echo 'Running ' . count($schedTasks) . ' tasks...' . PHP_EOL;
|
echo 'Running ' . count($schedTasks) . ' tasks...' . PHP_EOL;
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,13 @@ use Index\XNumber;
|
||||||
|
|
||||||
require_once __DIR__ . '/../misuzu.php';
|
require_once __DIR__ . '/../misuzu.php';
|
||||||
|
|
||||||
|
if(empty($msz->storageCtx->filesCtx->storage->localPath))
|
||||||
|
die(sprintf('No storage path is specified.%s', PHP_EOL));
|
||||||
|
if(!is_dir($msz->storageCtx->filesCtx->storage->localPath))
|
||||||
|
die(sprintf('Storage directory does not exist.%s', PHP_EOL));
|
||||||
|
if(fileowner($msz->storageCtx->filesCtx->storage->localPath) !== posix_getuid())
|
||||||
|
die(sprintf('Script must be run as the owner of the storage directory.%s', PHP_EOL));
|
||||||
|
|
||||||
$options = getopt('s', [
|
$options = getopt('s', [
|
||||||
'base62',
|
'base62',
|
||||||
], $restIndex);
|
], $restIndex);
|
||||||
|
|
|
@ -6,6 +6,13 @@ use Misuzu\Storage\Files\FileInfoGetFileField;
|
||||||
|
|
||||||
require_once __DIR__ . '/../misuzu.php';
|
require_once __DIR__ . '/../misuzu.php';
|
||||||
|
|
||||||
|
if(empty($msz->storageCtx->filesCtx->storage->localPath))
|
||||||
|
die(sprintf('No storage path is specified.%s', PHP_EOL));
|
||||||
|
if(!is_dir($msz->storageCtx->filesCtx->storage->localPath))
|
||||||
|
die(sprintf('Storage directory does not exist.%s', PHP_EOL));
|
||||||
|
if(fileowner($msz->storageCtx->filesCtx->storage->localPath) !== posix_getuid())
|
||||||
|
die(sprintf('Script must be run as the owner of the storage directory.%s', PHP_EOL));
|
||||||
|
|
||||||
$options = getopt('hsur:', [
|
$options = getopt('hsur:', [
|
||||||
'hash',
|
'hash',
|
||||||
'base62',
|
'base62',
|
||||||
|
|
|
@ -5,6 +5,13 @@ use Misuzu\Storage\Files\FileInfoGetFileField;
|
||||||
|
|
||||||
require_once __DIR__ . '/../misuzu.php';
|
require_once __DIR__ . '/../misuzu.php';
|
||||||
|
|
||||||
|
if(empty($msz->storageCtx->filesCtx->storage->localPath))
|
||||||
|
die(sprintf('No storage path is specified.%s', PHP_EOL));
|
||||||
|
if(!is_dir($msz->storageCtx->filesCtx->storage->localPath))
|
||||||
|
die(sprintf('Storage directory does not exist.%s', PHP_EOL));
|
||||||
|
if(fileowner($msz->storageCtx->filesCtx->storage->localPath) !== posix_getuid())
|
||||||
|
die(sprintf('Script must be run as the owner of the storage directory.%s', PHP_EOL));
|
||||||
|
|
||||||
$options = getopt('hsuv:', [
|
$options = getopt('hsuv:', [
|
||||||
'hash',
|
'hash',
|
||||||
'base62',
|
'base62',
|
||||||
|
|
|
@ -1,17 +1,12 @@
|
||||||
#!/usr/bin/env php
|
#!/usr/bin/env php
|
||||||
<?php
|
<?php
|
||||||
namespace Misuzu;
|
|
||||||
|
|
||||||
require_once __DIR__ . '/../misuzu.php';
|
require_once __DIR__ . '/../misuzu.php';
|
||||||
|
|
||||||
$path = $msz->tplCtx->cachePath;
|
if(empty($msz->tplCtx->cachePath))
|
||||||
if(empty($path))
|
|
||||||
die(sprintf('No cache path is specified.%s', PHP_EOL));
|
die(sprintf('No cache path is specified.%s', PHP_EOL));
|
||||||
|
if(!is_dir($msz->tplCtx->cachePath))
|
||||||
if(!is_dir($path))
|
|
||||||
die(sprintf('Cache directory does not exist.%s', PHP_EOL));
|
die(sprintf('Cache directory does not exist.%s', PHP_EOL));
|
||||||
|
if(fileowner($msz->tplCtx->cachePath) !== posix_getuid())
|
||||||
if(fileowner($path) !== posix_getuid())
|
|
||||||
die(sprintf('Script must be run as the owner of the cache directory.%s', PHP_EOL));
|
die(sprintf('Script must be run as the owner of the cache directory.%s', PHP_EOL));
|
||||||
|
|
||||||
echo `rm -rv {$path}`;
|
echo `rm -rv {$msz->tplCtx->cachePath}`;
|
||||||
|
|
|
@ -2,6 +2,13 @@
|
||||||
<?php
|
<?php
|
||||||
require_once __DIR__ . '/../misuzu.php';
|
require_once __DIR__ . '/../misuzu.php';
|
||||||
|
|
||||||
|
if(empty($msz->storageCtx->filesCtx->storage->localPath))
|
||||||
|
die(sprintf('No storage path is specified.%s', PHP_EOL));
|
||||||
|
if(!is_dir($msz->storageCtx->filesCtx->storage->localPath))
|
||||||
|
die(sprintf('Storage directory does not exist.%s', PHP_EOL));
|
||||||
|
if(fileowner($msz->storageCtx->filesCtx->storage->localPath) !== posix_getuid())
|
||||||
|
die(sprintf('Script must be run as the owner of the storage directory.%s', PHP_EOL));
|
||||||
|
|
||||||
if($argc <= 1)
|
if($argc <= 1)
|
||||||
die(sprintf('No uploader ID specified.%s', PHP_EOL));
|
die(sprintf('No uploader ID specified.%s', PHP_EOL));
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue