Skip to content

Commit

Permalink
fix: implementation issue in removeObjects() API (#980)
Browse files Browse the repository at this point in the history
  • Loading branch information
harshavardhana authored Nov 25, 2021
1 parent 36e30cc commit a73acef
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 18 deletions.
10 changes: 9 additions & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

const babel = require('gulp-babel')
const gulp = require('gulp')
const gulpIf = require('gulp-if')
const sourcemaps = require('gulp-sourcemaps')

const fs = require('fs')
Expand Down Expand Up @@ -59,11 +60,18 @@ exports.test = gulp.series(testCompile, () => {
}))
})

function isFixed(file) {
return file.eslint != null && file.eslint.fixed
}

exports.lint = () => {
const hasFixFlag = process.argv.slice(2).includes('--fix')
return gulp.src(['src/**/*.js', 'gulpfile.js'])
.pipe(eslint())
.pipe(eslint({fix: hasFixFlag}))
.pipe(eslint.format())
.pipe(eslint.failAfterError())
// if fixed, write the file to dest
.pipe(gulpIf(isFixed, gulp.dest('src/')))
}

exports.functionalTest = gulp.series(testCompile, () => {
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"compile": "gulp compile",
"test": "gulp test",
"lint": "gulp lint",
"lint-fix": "gulp lint --fix",
"prepublishOnly": "gulp test",
"functional": "gulp functionalTest",
"browserify": "gulp browserify",
Expand Down Expand Up @@ -56,6 +57,7 @@
"gulp": "^4.0.2",
"gulp-babel": "^8.0.0",
"gulp-eslint": "^6.0.0",
"gulp-if": "^3.0.0",
"gulp-mocha": "^6.0.0",
"gulp-sourcemaps": "^2.6.5",
"mocha": "^6.2.0",
Expand Down
19 changes: 8 additions & 11 deletions src/main/minio.js
Original file line number Diff line number Diff line change
Expand Up @@ -1253,7 +1253,7 @@ export class Client {
if (!isObject(listQueryOpts)) {
throw new TypeError('listQueryOpts should be of type "object"')
}

if (!isString(Delimiter)) {
throw new TypeError('Delimiter should be of type "string"')
}
Expand Down Expand Up @@ -1639,18 +1639,15 @@ export class Client {
const encoder = new TextEncoder()

async.eachSeries(result.listOfList, (list, callback) => {
var deleteObjects={"Delete":[{Quiet:true}], }
var objects=[]
list.forEach(function(value){
//Backward Compatibility
let entry
if(isObject(value)){
entry={"Object": [{"Key": value.name, "VersionId":value.versionId}]}
}else{
entry={"Object": [{"Key": value}]}
if (isObject(value)) {
objects.push({"Key": value.name, "VersionId": value.versionId})
} else {
objects.push({"Key": value})
}

deleteObjects["Delete"].push(entry)
})
let deleteObjects = {"Delete": {"Quiet": true, "Object": objects}}
const builder = new xml2js.Builder({ headless: true })
let payload = builder.buildObject(deleteObjects)
payload = encoder.encode(payload)
Expand Down Expand Up @@ -2352,7 +2349,7 @@ export class Client {
const builder = new xml2js.Builder({ headless:true,renderOpts:{'pretty':false},})
let payload = builder.buildObject(taggingConfig)
payload = encoder.encode(payload)

const requestOptions = { method, bucketName, query, headers }

if(objectName){
Expand Down
21 changes: 15 additions & 6 deletions src/test/functional/functional-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,15 @@ describe('functional tests', function() {
}

var tmpDir = os.tmpdir()

function readableStream(data) {
var s = new stream.Readable()
s._read = () => {}
s.push(data)
s.push(null)
return s
}

var traceStream

// FUNCTIONAL_TEST_TRACE env variable contains the path to which trace
Expand Down Expand Up @@ -1200,7 +1200,7 @@ describe('functional tests', function() {
.catch(done)
})

step(`removeObjects with non latin charactes`, done => {
step(`removeObjects with non latin characters`, done => {
client.removeObjects(bucketName, ['fileΩ'])
.then(() => done())
.catch(done)
Expand Down Expand Up @@ -1573,7 +1573,7 @@ describe('functional tests', function() {

describe('Versioning tests on a bucket for Deletion of Multiple versions', function () {
//Isolate the bucket/object for easy debugging and tracking.
const versionedBucketName = "minio-js-test-version-" + uuid.v4()
const versionedBucketName = "minio-js-test-version-" + uuid.v4()
const versioned_100kbObjectName = 'datafile-100-kB'
const versioned_100kb_Object = dataDir ? fs.readFileSync(dataDir + '/' + versioned_100kbObjectName) : Buffer.alloc(100 * 1024, 0)

Expand Down Expand Up @@ -1653,20 +1653,22 @@ describe('functional tests', function() {
})

describe('Bucket Tags API', ()=>{
//Isolate the bucket/object for easy debugging and tracking.
// Isolate the bucket/object for easy debugging and tracking.
const tagsBucketName = "minio-js-test-tags-" + uuid.v4()
before((done) => client.makeBucket(tagsBucketName, '', done))
after((done) => client.removeBucket(tagsBucketName, done))

describe('set, get and remove Tags on a bucket', function () {
step(`Set tags on a bucket_bucketName:${tagsBucketName}`, done => {
client.setBucketTagging(tagsBucketName, {'test-tag-key':'test-tag-value'}, (err) => {
if (err && err.code === 'NotImplemented') return done()
if (err) return done(err)
done()
})
})
step(`Get tags on a bucket_bucketName:${tagsBucketName}`, done => {
client.getBucketTagging(tagsBucketName, (err, tagList) => {
if (err && err.code === 'NotImplemented') return done()
if (err) return done(err)
if(isArray(tagList)) {
done()
Expand All @@ -1676,6 +1678,7 @@ describe('functional tests', function() {

step(`remove Tags on a bucket_bucketName:${tagsBucketName}`, done => {
client.removeBucketTagging(tagsBucketName, (err) => {
if (err && err.code === 'NotImplemented') return done()
if (err) return done(err)
done()
})
Expand Down Expand Up @@ -1706,13 +1709,15 @@ describe('functional tests', function() {

step(`putObjectTagging object_bucketName:${tagsBucketName}, objectName:${tagObjName},`, done => {
client.setObjectTagging(tagsBucketName, tagObjName, {'test-tag-key-obj':'test-tag-value-obj'}, (err) => {
if (err && err.code === 'NotImplemented') return done()
if (err) return done(err)
done()
})
})

step(`getObjectTagging object_bucketName:${tagsBucketName}, objectName:${tagObjName},`, done => {
client.getObjectTagging(tagsBucketName, tagObjName, (err, tagList) => {
if (err && err.code === 'NotImplemented') return done()
if (err) return done(err)
if(isArray(tagList)) {
done()
Expand All @@ -1722,6 +1727,7 @@ describe('functional tests', function() {

step(`removeObjectTagging on an object_bucketName:${tagsBucketName}, objectName:${tagObjName},`, done => {
client.removeObjectTagging(tagsBucketName, tagObjName, (err) => {
if (err && err.code === 'NotImplemented') return done()
if (err) return done()
done()
})
Expand Down Expand Up @@ -1800,6 +1806,7 @@ describe('functional tests', function() {

if(isVersioningSupported) {
client.removeObjectTagging(tagsVersionedBucketName, tagObjName, {versionId:versionId},(err) => {
if (err && err.code === 'NotImplemented') return done()
if (err) return done()
done()
})
Expand Down Expand Up @@ -2289,8 +2296,10 @@ describe('functional tests', function() {
isEncryptionSupported = false
return done()
}
if (err && err.code === 'ServerSideEncryptionConfigurationNotFoundError') {
return done()
}
if (err) return done(err)

done()
})
})
Expand Down

0 comments on commit a73acef

Please sign in to comment.