From 2d3c38685393eea3b01ea5cbc27cdb19e9f233eb Mon Sep 17 00:00:00 2001 From: Dmitry Bakaleinik Date: Wed, 14 Nov 2018 18:29:33 +0200 Subject: [PATCH] Handle 404 in head method for checking file availability Handle expires time when its nil --- lib/fog/aliyun/models/storage/files.rb | 1 + lib/fog/aliyun/requests/storage/get_object_http_url.rb | 2 +- lib/fog/aliyun/requests/storage/get_object_https_url.rb | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/fog/aliyun/models/storage/files.rb b/lib/fog/aliyun/models/storage/files.rb index f8cca49..a946b42 100644 --- a/lib/fog/aliyun/models/storage/files.rb +++ b/lib/fog/aliyun/models/storage/files.rb @@ -154,6 +154,7 @@ def head(key, _options = {}) directory.key + '/' + key end data = service.head_object(object).data + return nil if data[:status] == 404 lastModified = data[:headers]['Last-Modified'] last_modified = (Time.parse(lastModified).localtime if !lastModified.nil? && lastModified != '') diff --git a/lib/fog/aliyun/requests/storage/get_object_http_url.rb b/lib/fog/aliyun/requests/storage/get_object_http_url.rb index 7fef702..3c762c2 100644 --- a/lib/fog/aliyun/requests/storage/get_object_http_url.rb +++ b/lib/fog/aliyun/requests/storage/get_object_http_url.rb @@ -22,7 +22,7 @@ def get_object_http_url_public(object, expires, options = {}) location = get_bucket_location(bucket) if acl == 'private' - expires_time = (Time.now.to_i + expires).to_s + expires_time = (Time.now.to_i + (expires.nil? ? 0 : expires.to_i)).to_s resource = bucket + '/' + object signature = sign('GET', expires_time, nil, resource) 'http://' + bucket + '.' + location + '.aliyuncs.com/' + object + diff --git a/lib/fog/aliyun/requests/storage/get_object_https_url.rb b/lib/fog/aliyun/requests/storage/get_object_https_url.rb index 3ff7f5b..3cfe46c 100644 --- a/lib/fog/aliyun/requests/storage/get_object_https_url.rb +++ b/lib/fog/aliyun/requests/storage/get_object_https_url.rb @@ -22,7 +22,7 @@ def get_object_https_url_public(object, expires, options = {}) location = get_bucket_location(bucket) if acl == 'private' - expires_time = (Time.now.to_i + expires).to_s + expires_time = (Time.now.to_i + (expires.nil? ? 0 : expires.to_i)).to_s resource = bucket + '/' + object signature = sign('GET', expires_time, nil, resource) 'https://' + bucket + '.' + location + '.aliyuncs.com/' + object +