Return a promise that resolves if the bucket is available and
rejects if not.

@param {any} s3 S3 client object
@param {any} bucketName Bucket name
@returns Promise
498459
function bucketAccessible(s3, bucketName) {
  return new Promise(function(resolve, reject) {
    var params = {
      Bucket: bucketName
    };
    s3.headBucket(params, function(err, data) {
      if (err) {
        reject(new VError(err, 'S3 bucket not accessible'));
      } else {
        resolve();
      }
    });
  });
}
642285
function(appName) {

    // Validate inputs.
    return Promise.try(function() {
      if (appName && typeof appName !== 'string') {
        throw new TypeError('Invalid appName: ' + appName);
      }

      if (typeof appName === 'string') {
        appName = appName.replace(/-/g, '');
      }
    })

    .then(function() {
      return Promise.retry(function() {
        return docker.list(appName);
      });
    });

  }
332755
def remove_from_s3(self, file_name, bucket_name):
        
        try:
            self.s3_client.head_bucket(Bucket=bucket_name)
        except botocore.exceptions.ClientError as e:  # pragma: no cover
            # If a client error is thrown, then check that it was a 404 error.
            # If it was a 404 error, then the bucket does not exist.
            error_code = int(e.response['Error']['Code'])
            if error_code == 404:
                return False

        try:
            self.s3_client.delete_object(Bucket=bucket_name, Key=file_name)
            return True
        except (botocore.exceptions.ParamValidationError, botocore.exceptions.ClientError):  # pragma: no cover
            return False
925830
function (prefix, s3, callback) {
        if (!s3.client || !s3.bucket) {
            grunt.warn("Error: No client or bucket name defined.");
        }
        // List all of the objects in the bucket starting with prefix.
        var options = {BucketName : s3.bucket, Prefix: prefix || ''};
        s3.client.ListObjects(options, function(err, data) {
            if (err) {
                var message = (err.Body && err.Body.Error && err.Body.Error.Message) || 'Unknown';
                return callback({message: "Could not fetch bucket objects. " + message});
            }
            var bucketContents = data.Body.ListBucketResult.Contents;

            callback(null, bucketContents);
        });
    }
585614
function() {
		var that = this;
		return new Promise(function(resolve, reject) {
			that.resolve(function(err, val) {
				if (err) {
					reject(err);
				} else {
					resolve(val);
				}
			});
		});
	}
1374290
@Override
	public Promise call(String name, Tree params, Options opts, PacketStream stream, Context parent) {
		String targetID;
		int remaining;
		if (opts == null) {
			targetID = null;
			remaining = 0;
		} else {
			targetID = opts.nodeID;
			remaining = opts.retryCount;
		}
		return call(name, params, opts, stream, parent, targetID, remaining);
	}
521495
def bucket_exists?(bucket_name)
      begin
        s3 = AWS::S3.new
        s3.buckets[bucket_name].exists?

      rescue AWS::S3::Errors::SignatureDoesNotMatch => e
        raise AWSCredentialsInvalidError, 'AWS access credentials are invalid'
      rescue AWS::Errors::Base => s3e
        raise S3AccessError.new(s3e.http_response), s3e.message
      end
    end
1306918
function promiseWhen(promise, fulfilled, rejected) {
        // simply call rejected
        if (promise instanceof Reject) {
            // if there is a rejected , should always has! see when()
            rejected.call(promise, promise[PROMISE_VALUE]);
        } else {
            var v = promise[PROMISE_VALUE], pendings = promise[PROMISE_PENDINGS];
            if (pendings === undefined) {
                pendings = promise[PROMISE_PENDINGS] = [];
            }    // unresolved
                 // pushed to pending list
            // unresolved
            // pushed to pending list
            if (pendings) {
                pendings.push([
                    fulfilled,
                    rejected
                ]);
            } else if (isPromise(v)) {
                // rejected or nested promise
                promiseWhen(v, fulfilled, rejected);
            } else {
                // fulfilled value
                // normal value represents ok
                // need return user's return value
                // if return promise then forward
                if (fulfilled) {
                    fulfilled.call(promise, v);
                }
            }
        }
    }
669951
function(sModuleName) {
			//TODO: get rid of require async as soon as sap.ui.require has learned Promises as return value
			return new Promise(function(fnResolve, fnReject) {
				sap.ui.require([sModuleName], function(oModule) {
					fnResolve(oModule);
				},
				function(oError) {
					fnReject(oError);
				});
			});
		}
1297280
function() {
        return new Promise(function(resolve, reject) {
            try {
                let files;
                if(fileUtils.fileExists(resourceDir)) {
                    files = fs.readdirSync(resourceDir);
                    files = _.uniqBy(files, function (f) {
                        return path.basename(f, '.' + rc.tools.spec.file_ext);
                    }).map(function(f) { return path.join(resourceDir, f);});
                }
                if(!files) files = [];
                resolve(files);
            } catch (err) {
                reject(err);
            }
        }).then(function(files) {
            return promiseUtils.chain(rc.tools.inspect, function(err) {
                console.error(err);
                return false;
            })(files);
        });
    }
295763
function emptyBucket(aws, bucketName, keyPrefix) {
  return listObjectsInBucket(aws, bucketName).then(resp => {
    const contents = resp.Contents;
    let testPrefix = false,
      prefixRegexp;
    if (!contents[0]) {
      return Promise.resolve();
    } else {

      if (keyPrefix) {
        testPrefix = true;
        prefixRegexp = new RegExp('^' + keyPrefix);
      }
      const objects = contents.map(function(content) {
        return {Key: content.Key};
      }).filter(content => !testPrefix || prefixRegexp.test(content.Key));

      const params = {
        Bucket: bucketName,
        Delete: { Objects: objects }
      };

      return aws.request('S3', 'deleteObjects', params);
    }
  });
}
244119
function(success) {
				if (this.ended())
					throw new Error("promise already resolved or rejected");
				this._resolved = true;
				this._paused = false;
				this._initialised = true;
				if (typeof success !== "undefined")
					this._state.success = success;
				var instanceOfError = this._state.success instanceof Error;
				this._state.error = instanceOfError ? this._state.success : this._state.error;
				this._state.success = instanceOfError ? null : this._state.success;
				this._next();
				return this;
			}
1083723
def check_s3(self, bucket, element):  # pragma: no cover
        
        session = boto3.Session(profile_name=self.profile_name)
        s3 = session.resource('s3')

        try:
            s3.meta.client.head_bucket(Bucket=bucket)
        except ClientError:
            # If the bucket does not exists then simply use the original
            # I silently fail returning everything as it is in the url
            return False
        try:
            # If the key does not exists do not return False, but try to
            # create a readonly user in order to not have problems into the
            # travis environment.
            s3.Object(bucket, element).load()
        except ClientError:
            return False
        else:
            return True
948514
function (name, args) {
        var ready = when.defer();
        var that = this;

        when(this.ensureWeHaveIntrospectionData()).then(
            function () {
                var buf = that._transformArguments(name, args);
                if (buf) {
                    ready.resolve(buf);
                }
                else {
                    //NOTE! The API looks for "Unknown Function" in the error response.
                    ready.reject("Unknown Function: " + name);
                }
            },
            function (msg) {
                ready.reject(msg);
            }
        );

        return ready.promise;
    }
496296
function streamFile(namespace, fileName) {
  var file;
  if (namespace) {
    file = path.join(namespace, fileName);
  } else {
    file = fileName;
  }
  var deferred = q.defer();
  var paramsStream = {
    Bucket: config.bucket,
    Key: file
  };
  try {
    var stream = awsClient.downloadStream(paramsStream);
    deferred.resolve(stream);
  } catch (error) {
    console.log(error);
    deferred.reject(error);
  }
  return deferred.promise;
}
218683
function() {
                var def = _promise.deferred();

                _fs.exists(_folderPath, function(exists) {
                    if (exists) {
                        def.resolve();
                    } else {
                        _fs.mkdir(_folderPath, function(err) {
                            if (!err) {
                                def.resolve();
                            } else {
                                def.reject();
                            }
                        });
                    }
                });

                return def.promise();
            }
484508
function (options) {
        var s3 = {};
        s3.client = connectToS3(options);
        s3.bucket = options.bucket || '';
        return s3;
    }