private void CreateFileAtomicallyWithOverWrite()

in src/main/java/com/microsoft/azure/datalake/store/ADLStoreClient.java [303:360]


    private void CreateFileAtomicallyWithOverWrite(String path, String octalPermission, boolean createParent, String leaseId) throws IOException {
        boolean checkExists = true;
        RequestOptions opts = new RequestOptions();
        opts.retryPolicy = makeExponentialBackoffPolicy();
        opts.timeout = this.timeout;
        OperationResponse resp = new OperationResponse();

        DirectoryEntry entry = Core.getFileStatus(path, UserGroupRepresentation.OID, this, opts, resp);
        if (!resp.successful) {
            if (resp.httpResponseCode == 404 && resp.remoteExceptionName.contains("FileNotFoundException")) {
                checkExists = false;
            } else {
                throw getExceptionFromResponse(resp, "Error getting info for file " + path);
            }
        }

        if (checkExists && entry.type == DirectoryEntryType.DIRECTORY) {
            throw new ADLException("Cannot overwrite directory");
        }

        if(checkExists) {
            opts = new RequestOptions();
            opts.retryPolicy = new ExponentialBackoffPolicy();
            opts.timeout = this.timeout;
            resp = new OperationResponse();
            Core.checkAccess(path, "-w-", this, opts, resp);
            if (!resp.successful) {
                if (resp.httpResponseCode == 404 && resp.remoteExceptionName.contains("FileNotFoundException")) {
                    checkExists = false;
                } else {
                    throw getExceptionFromResponse(resp, "Error checking access for " + path);
                }
            }
            if (checkExists) {
                opts = new RequestOptions();
                opts.retryPolicy = new ExponentialBackoffPolicy();
                opts.timeout = this.timeout;
                resp = new OperationResponse();
                Core.delete(path, false, entry.fileContextId, this, opts, resp); // conditional delete
                if (!resp.successful) {
                    throw getExceptionFromResponse(resp, "Error deleting the file for create+overwrite " + path);
                }
            }
        }

        opts = new RequestOptions();
        opts.retryPolicy = new ExponentialBackoffPolicy();
        opts.timeout = this.timeout;
        resp = new OperationResponse();
        Core.create(path, false, octalPermission, null, 0, 0, leaseId,
                leaseId, createParent, SyncFlag.DATA, this, opts, resp);
        if (!resp.successful) {
            if(resp.httpResponseCode == 403 && resp.remoteExceptionName.contains("FileAlreadyExistsException")){
                return;
            }
            throw this.getExceptionFromResponse(resp, "Error creating file " + path);
        }
    }