Git Product home page Git Product logo

Comments (1)

dammitjanet avatar dammitjanet commented on August 16, 2024

it is created because the Blob storage provider you are using is not one that supports IHierarchicalBlobStorage so the only way to create a folder, is to put an empty file in it, otherwise the folder won't exist.

You can name it something different as the method signature support providing a different name but I've found that in cases where the storage provider doesn't actually support IHierarchicalBlobStorage, that they support full path and folder creation when creating files and actually don't need to have folders created prior to writing of files. if your implementation is only targetting one of these, then you can either explicitly ignore the files, or refactor to not use the CreateFolderAsync extension method

		/// <summary>
		/// Creates a new folder in this storage. If storage supports hierarchy, the folder is created as is, otherwise a folder is created by putting a dummy zero size file in that folder.
		/// </summary>
		/// <param name="blobStorage"></param>
		/// <param name="folderPath">Path to the folder</param>
		/// <param name="dummyFileName">If storage doesn't support hierary, you can override the dummy file name created in that empty folder.</param>
		/// <param name="cancellationToken"></param>
		/// <returns></returns>
		public static async Task CreateFolderAsync(
		   this IBlobStorage blobStorage, string folderPath, string dummyFileName = null, CancellationToken cancellationToken = default) {
			if (blobStorage is IHierarchicalBlobStorage hierarchicalBlobStorage) {
				await hierarchicalBlobStorage.CreateFolderAsync(folderPath, cancellationToken).ConfigureAwait(false);
			}
			else {
				string fullPath = StoragePath.Combine(folderPath, dummyFileName ?? ".empty");

				// Check if the file already exists before we try to create it to prevent 
				// AccessDenied exceptions if two processes are creating the folder at the same time.
				if (await blobStorage.ExistsAsync(fullPath)) {
					return;
				}

				await blobStorage.WriteTextAsync(
				   fullPath,
				   "created as a workaround by FluentStorage when creating an empty parent folder",
				   null,
				   cancellationToken).ConfigureAwait(false);
			}
		}


from fluentstorage.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.