Comment 0 for bug 1901047

Revision history for this message
Robert C Jennings (rcj) wrote :

We have a directory tree with empty directories. When uploading the tree to swift objects are created corresponding to directories that are empty. Directories with contents do not have objects created. This behavior is inconsistent and creates issues on download as follows:

# Create a directory tree with some empty paths
mkdir -p path1/path1a
mkdir -p path1/path1b
touch path1/path1a/file

# Upload tree to swift
swift upload $bucket --object-name $upload_prefix --skip-identical .

# Add a file to an empty directory
touch path1/path1b/file2

# Upload to swift
swift upload bucket --object-name upload_prefix --skip-identical .

# Download the tree from swift
mkdir out
swift download $bucket --prefix $upload_prefix --remove-prefix --skip-identical --output-dir out
Command failed with error code 1 : Error downloading object 'bucket/upload_prefix/path1/path1b': [Errno 21] Is a directory: u'out/path1/path1b'
Traceback (most recent call last):
   File "./sync_images_from_swift.py", line 118, in <module>
     main()
   File "./sync_images_from_swift.py", line 114, in main
     args.serial, args.target_directory)
   File "./sync_images_from_swift.py", line 75, in perform_sync
     _download_build(swift_suite, serial, build_download_location)
   File "./sync_images_from_swift.py", line 28, in _download_build
     target_directory)
   File "/srv2/jenkins/jobs/Alan-16.04-Download-Daily-Sync-From-Swift/workspace/swiftlib.py", line 139, in run_swift_command
     raise SwiftSubprocessError(error_message)
 swiftlib.SwiftSubprocessError: Command failed with error code 1 : Error downloading object 'cloud-images/xenial/20201021/public/unpacked': [Errno 21] Is a directory: u'out/path1/path1b'

So what has happened is swift created a zero byte object for an empty dir. On download it will create a zero byte *file* for that object. If someone uploads an object under the previously-empty path then the download fails because we can't create a directory because swift download has already created a file with the same name due to the empty object.

We've had to pepper our code with `find . -type d -empty -delete` prior to swift upload to avoid this issue but that's a pain.