Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

「File::copy_dir」 File security permissions #2028

Closed
Himakuma opened this issue Oct 4, 2016 · 3 comments
Closed

「File::copy_dir」 File security permissions #2028

Himakuma opened this issue Oct 4, 2016 · 3 comments

Comments

@Himakuma
Copy link

Himakuma commented Oct 4, 2016

・Not copy file security permissions.
・Copy directory security permissions.

public static function copy($path, $new_path, $source_area = null, $target_area = null)
{
    $path      = static::instance($source_area)->get_path($path);
    $new_path  = static::instance($target_area ?: $source_area)->get_path($new_path);

    if ( ! is_file($path))
    {
        throw new \InvalidPathException('Cannot copy file: given path: "'.$path.'" is not a file.');
    }
    elseif (file_exists($new_path))
    {
        throw new \FileAccessException('Cannot copy file: new path: "'.$new_path.'" already exists.');
    }
    return copy($path, $new_path); ←←←←←←←←←←←←← Why not copy file security permissions?
}

↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓


public static function copy($path, $new_path, $source_area = null, $target_area = null)
{
    $path      = static::instance($source_area)->get_path($path);
    $new_path  = static::instance($target_area ?: $source_area)->get_path($new_path);

    if ( ! is_file($path))
    {
        throw new \InvalidPathException('Cannot copy file: given path: "'.$path.'" is not a file.');
    }
    elseif (file_exists($new_path))
    {
        throw new \FileAccessException('Cannot copy file: new path: "'.$new_path.'" already exists.');
    }
    if (copy($path, $new_path)) {
        return chmod($new_path, fileperms($path)); 
    }
    return false;
}

@Himakuma Himakuma changed the title File::copy_dir] 「File::copy_dir」 File security permissions Oct 4, 2016
@WanWizard
Copy link
Member

Does that always succeed? Or is there a chance of the chmod failing, in which case a try/catch block is needed to handle the failure.

@Himakuma
Copy link
Author

Himakuma commented Oct 4, 2016

I am Japanese.
Sorry. I am not good at English.
Code is sample.

OK:Copy directory security permissions.
Bug:Not copy file security permissions.

Why copy authority the directory only?

@WanWizard
Copy link
Member

I understand that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants