in AdlsDotNetSDK/ADLSClient.cs [609:669]
private async Task CreateFileAtomicallyWithOverWrite(string path, string octalPermission, bool createParent, string leaseId, CancellationToken cancelToken = default(CancellationToken))
{
bool checkExists = true;
OperationResponse resp = new OperationResponse();
var entry = await Core.GetFileStatusAsync(path, UserGroupRepresentation.ObjectID, this, new RequestOptions(GetPerRequestTimeout(), new ExponentialRetryPolicy()), resp).ConfigureAwait(false);
if (!resp.IsSuccessful)
{
if (resp.HttpStatus == HttpStatusCode.NotFound && resp.RemoteExceptionName.Contains("FileNotFoundException"))
{
checkExists = false;
}
else
{
throw GetExceptionFromResponse(resp, "Error getting info for file " + path);
}
}
if (checkExists && entry.Type == DirectoryEntryType.DIRECTORY)
{
throw new AdlsException("Cannot overwrite directory "+path);
}
if(checkExists)
{
resp = new OperationResponse();
await Core.CheckAccessSync(path, "-w-", this, new RequestOptions(GetPerRequestTimeout(), new ExponentialRetryPolicy()), resp).ConfigureAwait(false);
if (!resp.IsSuccessful)
{
if (resp.HttpStatus == HttpStatusCode.NotFound && resp.RemoteExceptionName.Contains("FileNotFoundException"))
{
checkExists = false;
}
else
{
throw GetExceptionFromResponse(resp, "Error checking access for " + path);
}
}
if (checkExists)
{
resp = new OperationResponse();
await Core.DeleteAsync(path, false, entry.FileContextID, this, new RequestOptions(GetPerRequestTimeout(), new ExponentialRetryPolicy()), resp).ConfigureAwait(false); // conditional delete
if (!resp.IsSuccessful)
{
throw GetExceptionFromResponse(resp, "Error deleting the file for create+overwrite " + path);
}
}
}
resp = new OperationResponse();
await Core.CreateAsync(path, false, octalPermission, leaseId, leaseId, createParent, SyncFlag.DATA, null, -1, 0, this, new RequestOptions(GetPerRequestTimeout(), new ExponentialRetryPolicy()), resp, cancelToken).ConfigureAwait(false);
if (!resp.IsSuccessful)
{
if (resp.HttpStatus == HttpStatusCode.Forbidden && resp.RemoteExceptionName.Contains("FileAlreadyExistsException"))
{
return;
}
throw GetExceptionFromResponse(resp, $"Error in creating file {path}.");
}
}