Joe
Joe

Reputation: 49

python script, folder permissions, created a folder with wrong permissions

I have the following function, when I run it, I get the folder created with the following permissions and it's not what I explicitly set:

Code:

def copy(src, dst):
    if not os.path.isdir(os.path.dirname(src)):
        print('No source directory to copy from')
    else:
        if not os.path.isdir(dst):
            print('No destination directory to copy files to')
            print('Creating destination directory')
            os.umask(0o002)
            os.mkdir(dst, mode=0o777)
            print('Destination directory created')
    shutil.copy2(src, dst)
    os.chmod(dst, stat.S_IEXEC)
    os.chmod(dst, stat.S_IXGRP)
    print("copied "+str(src)+" --> "+str(dst))

The folder is created with the following:

# ls -la /tmp/
total 16
drwxrwxr-x  4 userx  userx  4096 Jul 25 10:21 .
drwxrwxrwt 25 root root 4096 Jul 25 10:21 ..
d-----x---  2 userx  userx  4096 Jul 25 10:21 tmpdir

Any ideas? i.e. the mask on the system is 0022

Upvotes: 0

Views: 22

Answers (0)

Related Questions