def mkdir(fs: GDriveFileSystem, path, create_parents=True):
"""Create directory entry at path"""
if fs.exists(path):
raise FileExistsError(path)
dst_id = fs._get_item_id(fs._parent(path), create=create_parents)
basename = posixpath.basename(path.rstrip("/"))
fs._gdrive_create_dir(dst_id, basename)
# create a GDriveFileSystem instance with a path that point to an empy folder
root = "root/tmp/"
fs = GDriveFileSystem(root, auth)
# dump the cache
print(json.dumps(fs._ids_cache, indent=4))
{
"dirs": {
"tmp": [
"1BClMfgL7BMV61-5SdWAvc8njvkPgicyx"
]
},
"ids": {
"1BClMfgL7BMV61-5SdWAvc8njvkPgicyx": "tmp"
},
"root_id": "1BClMfgL7BMV61-5SdWAvc8njvkPgicyx"
}
# create a folder
folder = posixpath.join(root, "folder")
mkdir(fs, folder)
# the cache did not change
print(json.dumps(fs._ids_cache, indent=4))
{
"dirs": {
"tmp": [
"1BClMfgL7BMV61-5SdWAvc8njvkPgicyx"
]
},
"ids": {
"1BClMfgL7BMV61-5SdWAvc8njvkPgicyx": "tmp"
},
"root_id": "1BClMfgL7BMV61-5SdWAvc8njvkPgicyx"
}
# use the ls method to get the content of the folder we just created
print(fs.ls(folder))
[]
# there is a new entry in the cache: "root/tmp/folder"
print(json.dumps(fs._ids_cache, indent=4))
{
"dirs": {
"tmp": [
"1BClMfgL7BMV61-5SdWAvc8njvkPgicyx"
],
"root/tmp/folder": [
"1VKRRnGmZm_Dvmn0G8xQjqwQxbZ9vW0Hf"
]
},
"ids": {
"1BClMfgL7BMV61-5SdWAvc8njvkPgicyx": "tmp",
"1VKRRnGmZm_Dvmn0G8xQjqwQxbZ9vW0Hf": "root/tmp/folder"
},
"root_id": "1BClMfgL7BMV61-5SdWAvc8njvkPgicyx"
}
As we can see, there is an inconsistency between items added in the initialization phase of the cache and items added by ls:
items added on the initialization of _ids_cache does not have the root/ prefix
code
https://github.com/iterative/PyDrive2/blob/b700387d05b4ef853607bc54ce0561d571456fc6/pydrive2/fs/spec.py#L247-L266
items added by ls have the root/ prefix
code
https://github.com/iterative/PyDrive2/blob/b700387d05b4ef853607bc54ce0561d571456fc6/pydrive2/fs/spec.py#L427-L467
Consider this minimal working example:
The
mkdir
method is from #222As we can see, there is an inconsistency between items added in the initialization phase of the cache and items added by ls:
_ids_cache
does not have theroot/
prefixcode
https://github.com/iterative/PyDrive2/blob/b700387d05b4ef853607bc54ce0561d571456fc6/pydrive2/fs/spec.py#L247-L266ls
have theroot/
prefixcode
https://github.com/iterative/PyDrive2/blob/b700387d05b4ef853607bc54ce0561d571456fc6/pydrive2/fs/spec.py#L427-L467Is this the expected behavior?