Skip to content

Commit ca91463

Browse files
committed
fix for creating directory
1 parent be84e02 commit ca91463

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

jupyter_drives/manager.py

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -274,21 +274,22 @@ async def new_file(self, drive_name, path, is_dir):
274274
try:
275275
# eliminate leading and trailing backslashes
276276
path = path.strip('/')
277+
print('isDir: ', is_dir)
277278

278279
if is_dir == False or self._config.provider != 's3':
279280
# TO DO: switch to mode "created", which is not implemented yet
280281
await obs.put_async(self._content_managers[drive_name]["store"], path, b"", mode = "overwrite")
282+
metadata = await obs.head_async(self._content_managers[drive_name]["store"], path)
283+
data = {
284+
"path": path,
285+
"content": "",
286+
"last_modified": metadata["last_modified"].isoformat(),
287+
"size": metadata["size"]
288+
}
281289
elif is_dir == True and self._config.provider == 's3':
282290
# create an empty directory through boto, as obstore does not allow it
283-
self._create_empty_directory(drive_name, path)
284-
metadata = await obs.head_async(self._content_managers[drive_name]["store"], path)
285-
286-
data = {
287-
"path": path,
288-
"content": "",
289-
"last_modified": metadata["last_modified"].isoformat(),
290-
"size": metadata["size"]
291-
}
291+
data = self._create_empty_directory(drive_name, path)
292+
292293
except Exception as e:
293294
raise tornado.web.HTTPError(
294295
status_code= httpx.codes.BAD_REQUEST,
@@ -526,19 +527,28 @@ def _create_empty_directory(self, drive_name, path):
526527
drive_name: name of drive where to create object
527528
path: path of new object
528529
"""
530+
data = {}
529531
try:
530532
location = self._content_managers[drive_name]["location"]
531533
if location not in self._s3_clients:
532534
self._s3_clients[location] = self._s3_session.client('s3', location)
533535

534-
self._s3_clients[location].put_object(Bucket=drive_name, Key=path+'/')
536+
self._s3_clients[location].put_object(Bucket = drive_name, Key = path + '/')
537+
metadata = self._s3_clients[location].head_object(Bucket = drive_name, Key = path + '/')
538+
539+
data = {
540+
"path": path,
541+
"content": "",
542+
"last_modified": metadata["LastModified"].isoformat(),
543+
"size": 0
544+
}
535545
except Exception as e:
536546
raise tornado.web.HTTPError(
537547
status_code= httpx.codes.BAD_REQUEST,
538548
reason=f"The following error occured when creating the directory: {e}",
539549
)
540550

541-
return
551+
return data
542552

543553
async def _delete_directories(self, drive_name, path):
544554
"""Helping function to delete directories, when dealing with S3 buckets.

0 commit comments

Comments
 (0)