How any web hosting site protect files from deleting?

Viewed 70

I am creating a python code testing (pytest) website using django and deploy on azure and I just test a code and try to delete files in the root directory of my project using shutil.rmtree() but It returns code like this

============================= test session starts ==============================
platform linux -- Python 3.9.7, pytest-7.1.2, pluggy-1.0.0
rootdir: /tmp/8da77f5e80b846d
collected 1 item

codes/test_with_pytest.py F                                              [100%]

=================================== FAILURES ===================================
_______________________________ test_check_test ________________________________

    def test_check_test():
        from .code import check_test
>       assert check_test() == 90

/tmp/8da77f5e80b846d/codes/test_with_pytest.py:3: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
/tmp/8da77f5e80b846d/codes/code.py:7: in check_test
    shutil.rmtree('/')
/opt/python/3.9.7/lib/python3.9/shutil.py:726: in rmtree
    _rmtree_safe_fd(fd, path, onerror)
/opt/python/3.9.7/lib/python3.9/shutil.py:663: in _rmtree_safe_fd
    _rmtree_safe_fd(dirfd, fullname, onerror)
/opt/python/3.9.7/lib/python3.9/shutil.py:663: in _rmtree_safe_fd
    _rmtree_safe_fd(dirfd, fullname, onerror)
/opt/python/3.9.7/lib/python3.9/shutil.py:663: in _rmtree_safe_fd
    _rmtree_safe_fd(dirfd, fullname, onerror)
/opt/python/3.9.7/lib/python3.9/shutil.py:663: in _rmtree_safe_fd
    _rmtree_safe_fd(dirfd, fullname, onerror)
/opt/python/3.9.7/lib/python3.9/shutil.py:683: in _rmtree_safe_fd
    onerror(os.unlink, fullname, sys.exc_info())
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

topfd = 15, path = '/usr/local/azure/certs'
onerror = .onerror at 0x7efce0496310>

    def _rmtree_safe_fd(topfd, path, onerror):
        try:
            with os.scandir(topfd) as scandir_it:
                entries = list(scandir_it)
        except OSError as err:
            err.filename = path
            onerror(os.scandir, path, sys.exc_info())
            return
        for entry in entries:
            fullname = os.path.join(path, entry.name)
            try:
                is_dir = entry.is_dir(follow_symlinks=False)
            except OSError:
                is_dir = False
            else:
                if is_dir:
                    try:
                        orig_st = entry.stat(follow_symlinks=False)
                        is_dir = stat.S_ISDIR(orig_st.st_mode)
                    except OSError:
                        onerror(os.lstat, fullname, sys.exc_info())
                        continue
            if is_dir:
                try:
                    dirfd = os.open(entry.name, os.O_RDONLY, dir_fd=topfd)
                except OSError:
                    onerror(os.open, fullname, sys.exc_info())
                else:
                    try:
                        if os.path.samestat(orig_st, os.fstat(dirfd)):
                            _rmtree_safe_fd(dirfd, fullname, onerror)
                            try:
                                os.rmdir(entry.name, dir_fd=topfd)
                            except OSError:
                                onerror(os.rmdir, fullname, sys.exc_info())
                        else:
                            try:
                                # This can only happen if someone replaces
                                # a directory with a symlink after the call to
                                # os.scandir or stat.S_ISDIR above.
                                raise OSError("Cannot call rmtree on a symbolic "
                                              "link")
                            except OSError:
                                onerror(os.path.islink, fullname, sys.exc_info())
                    finally:
                        os.close(dirfd)
            else:
                try:
>                   os.unlink(entry.name, dir_fd=topfd)
E                   OSError: [Errno 30] Read-only file system: 'Microsoft_Azure_TLS_Issuing_CA_01.crt'

/opt/python/3.9.7/lib/python3.9/shutil.py:681: OSError
----------------------------- Captured stdout call -----------------------------
/tmp/8da77f5e80b846d
/
=========================== short test summary info ============================
FAILED codes/test_with_pytest.py::test_check_test - OSError: [Errno 30] Read-...
============================== 1 failed in 0.45s ===============================

and it didn't delete a file. Also, I interpreted os.chdir("..") and then tried to delete files this time code even don't run and give a server-side error. This error didn't solve by refreshing the page instead I had to restart azure server.

How Azure or any other web hosting platform protects files from getting deleted and if any file delete then which files may get deleted?

0 Answers
Related