Skip to content

Conversation

samialfattani
Copy link

  • this change needed whever the current os platform is different thn s3 cloud platform. In this case the os.path.pathnorm() will not work properly since it treats storage as it is placed in the current system.

  • Before this PR, browsing deep path in FileAdmin view such as /admin/fileadmins3/b/xx/yy/zz responses 404 code. This can happend only when the current os is "Windows" and the cloud s3 is "non-Windows" and vise versa.

- this change needed whever the current os platform is different thn s3 cloud platform. In this case the os.path.pathnorm() will not work properly since it treats storage as it is placed in the current system.

- without this change, browsing deep path in FileAdmin view such as /admin/fileadmins3/b/xx/yy/zz will response 404 code.
@ElLorans
Copy link
Contributor

Thanks for the PR! Looks like you used python 3.10 or above so tests on 3.9 are failing because of the pipe operator | . In python 3.9, you must use typing.Union. Do you think we can try to solve the issue without an additional argument by detecting local os and cloud os?

@ElLorans
Copy link
Contributor

From a quick google search, posixpath.normpath(base_path) looks promising.
Can you try something like this, without using a new on_windows parameter?

def is_in_folder(self, base_path: str, directory: T_PATH_LIKE) -> bool:
        """
        Verify that `directory` is in `base_path` folder
        :param base_path:
            Base directory path
        :param directory:
            Directory path to check
        """
        base_path = posixpath.normpath(base_path)
        directory = posixpath.normpath(directory)
        return directory.startswith(base_path)

@samialfattani
Copy link
Author

samialfattani commented Sep 14, 2025

From a quick google search, posixpath.normpath(base_path) looks promising.

as i said , the os.path.normpath() returns path with '/' or '\\' based on the current os no mater what the os of s3 cloud is !! if we assume both of them are Windows or both of them are Linux, then no need for this PR! The test fails only if:

current os (Windows) with s3 cloud (Linux)
or
current os (Linux) with s3 cloud (Windows)

in these cases we should initiate the S3FileAdmin() object specifying what is the operating system is used on the clould. I think such information is hard to retrive automatically unless if boto3 client support such function.

posixpath.normpath() returns the path in Unix style even if the os is Windows which is not what we are looking for!

what we need is letting s3FileAdmin view works based on s3 cloud's os while other local FileAdmin views works based on the local os which can be defined automatically by platform.system()

@ElLorans
Copy link
Contributor

I didn't know you could have Windows on S3. Do you have any docs about it? My understanding was that S3 has only one path convention, so posixpath would solve the issue since it returns always the same result from both Windows and Linux

@samialfattani
Copy link
Author

samialfattani commented Sep 15, 2025

i don't know either, i am just asumming worst case senario.

however, this article shows that it is possible using what so called FSx which is something different from S3 as i believe.

Anyway, on_windows parameter Must be added. even if S3 uses posixpath then we have to tell BaseFileAdmin to behave differently. Another option, we can just add extra check of the storage type in the BaseFileAdmin.__init__() where it sets self._on_windows to False if the storage type is S3Storage

@samialfattani
Copy link
Author

keep in mind that the changes of normpath() are made on BaseFileAdmin not on S3FileAdmin class which make it mandatory to specify on_windows explicitly since the project might have 2 FileAdmin views one to browse local folder and the other for browsing s3 storage.

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

Successfully merging this pull request may close these issues.

2 participants