{"record":{"id":"de7cef66d0b63377","repo":"yiisoft/yii2","slug":"trying-to-copy-a-directory-to-itself-or-a-subdirec","errorCode":null,"errorMessage":"Trying to copy a directory to itself or a subdirectory.","messagePattern":"Trying to copy a directory to itself or a subdirectory\\.","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"framework/helpers/BaseFileHelper.php","lineNumber":382,"sourceCode":"     *   If the callback returns false, the copy operation for the sub-directory or file will be cancelled.\n     *   The signature of the callback should be: `function ($from, $to)`, where `$from` is the sub-directory or\n     *   file to be copied from, while `$to` is the copy target.\n     * - afterCopy: callback, a PHP callback that is called after each sub-directory or file is successfully copied.\n     *   The signature of the callback should be: `function ($from, $to)`, where `$from` is the sub-directory or\n     *   file copied from, while `$to` is the copy target.\n     * - copyEmptyDirectories: boolean, whether to copy empty directories. Set this to false to avoid creating directories\n     *   that do not contain files. This affects directories that do not contain files initially as well as directories that\n     *   do not contain files at the target destination because files have been filtered via `only` or `except`.\n     *   Defaults to true. This option is available since version 2.0.12. Before 2.0.12 empty directories are always copied.\n     * @throws InvalidArgumentException if unable to open directory\n     */\n    public static function copyDirectory($src, $dst, $options = [])\n    {\n        $src = static::normalizePath($src);\n        $dst = static::normalizePath($dst);\n\n        if ($src === $dst || strpos($dst, $src . DIRECTORY_SEPARATOR) === 0) {\n            throw new InvalidArgumentException('Trying to copy a directory to itself or a subdirectory.');\n        }\n        $dstExists = is_dir($dst);\n        if (!$dstExists && (!isset($options['copyEmptyDirectories']) || $options['copyEmptyDirectories'])) {\n            static::createDirectory($dst, isset($options['dirMode']) ? $options['dirMode'] : 0775, true);\n            $dstExists = true;\n        }\n\n        $handle = opendir($src);\n        if ($handle === false) {\n            throw new InvalidArgumentException(\"Unable to open directory: $src\");\n        }\n        if (!isset($options['basePath'])) {\n            // this should be done only once\n            $options['basePath'] = realpath($src);\n            $options = static::normalizeOptions($options);\n        }\n        while (($file = readdir($handle)) !== false) {\n            if ($file === '.' || $file === '..') {","sourceCodeStart":364,"sourceCodeEnd":400,"githubUrl":"https://github.com/yiisoft/yii2/blob/66f00d18a29b520f85e8e8f1e32d1e7e7b556cac/framework/helpers/BaseFileHelper.php#L364-L400","documentation":"Error \"Trying to copy a directory to itself or a subdirectory.\" thrown in yiisoft/yii2.","triggerScenarios":"Thrown at framework/helpers/BaseFileHelper.php:382 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"66f00d18a29b520f85e8e8f1e32d1e7e7b556cac","analyzedAt":"2026-08-17T05:17:23.470Z","schemaVersion":2},"datasetVersion":"2026-08-17T09:17:11.063Z"}