inab / inab/openVRE-core-dev

Embedded calls to `find` in cleanUsersData.php do not scale up

Open
#19 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
PHP
Stars
0
Forks
3
Avg merge
2d 4h
Merged PRs (30d)
4

Description

I have found in the logs emitted by cleanUsersData.php from other openVRE deployments messages like next:

Looking for temporary data (/gpfs/vre/userdata//*/*/.tmp/)
-- find /gpfs/vre/userdata//*/*/.tmp/  -maxdepth 1  -mtime +7 -type f  -exec rm -fv {} \;
sh: 1: find: Argument list too long
-- find /gpfs/vre/userdata//*/*/.tmp/  -maxdepth 1  -mtime +7 -type d -name '?*_[0-9]*'  -exec rm -Rfv {} \;
sh: 1: find: Argument list too long
-- find /gpfs/vre/userdata//*/*/.tmp/  -maxdepth 1  -size +2G -mtime -7 -type f -name '*tar.gz'  -exec rm -fv {} \;
sh: 1: find: Argument list too long

And they are happening when the user data directory from that openVRE deployment contains too many entries (more than the number of parameters which can passed to a program from command line). These are the blamed lines:

https://github.com/inab/openVRE-core-dev/blob/d8d98c868fa27a5f49de80824d94e48633b5c7bb/front_end/openVRE/scripts/maintainance/cleanUsersData.php#L341-L363

This issue can be fixed using something similar to next command line, where find command delegates on xargs calling nested find commands, so no wildcard expansion happens:

    if(substr($GLOBALS['tmpUser_dir'], -1) == "/") {
        $tmpuser_dir = substr($GLOBALS['tmpUser_dir'], 0, -1);
    } else {
        $tmpuser_dir = $GLOBALS['tmpUser_dir'];
    }

    $cmd = "find ".$GLOBALS['dataDir']." -type d -name ".$tmpuser_dir." -print0 | xargs -0 -I{.} find {.} -maxdepth 1  -mtime +".$caduca_strict." -type f ";
    if ($dry_run === false) {
        $cmd.= " -exec rm -fv {} \\;";
    }
    print "-- $cmd\n";
    system($cmd);

    $cmd = "find ".$GLOBALS['dataDir']." -type d -name ".$tmpuser_dir." -print0 | xargs -0 -I{.} find {.} -maxdepth 1  -mtime +".$caduca_strict." -type d -name '?*_[0-9]*' ";
    if ($dry_run === false) {
        $cmd.= " -exec rm -Rfv {} \\;";
    }
    print "-- $cmd\n";
    system($cmd);

    $cmd = "find ".$GLOBALS['dataDir']." -type d -name ".$tmpuser_dir." -print0 | xargs -0 -I{.} find {.} -maxdepth 1  -size +2G -mtime -".$caduca_strict." -type f -name '*tar.gz' ";
    if ($dry_run === false) {
        $cmd.= " -exec rm -fv {} \\;";
    }
    print "-- $cmd\n";
    system($cmd);

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in front_end/openVRE/scripts/maintainance/cleanUsersData.php at lines 341-363 and inspect the three logged find commands and their dry-run paths. Reproduce the failure with a data directory containing enough entries to exceed command-line limits, then verify the cleanup commands work for files, temporary directories, and tar archives without wildcard expansion.

Written by the indexing model from the issue text.

Assessment

Tech stack
php, shell
Domain
devops, infrastructure
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.