MathieuLoutre / grunt-aws-s3

Grunt plugin to interact with AWS S3 using the AWS SDK
MIT License
294 stars 90 forks source link

Can't run differential delete #99

Open benblamey opened 8 years ago

benblamey commented 8 years ago

I'm currently using the "upload" action; without any problem. When I try to perform a differential delete, I get the following error: Fatal error: Differential delete needs a "cwd"

This is my Gruntfile.js

module.exports = function(grunt) {
  grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),

    aws_s3: {
      options: {
        region: 'eu-west-1',
        uploadConcurrency: 5,
        downloadConcurrency: 5,
      },

      dist: {
        options: {
          bucket: 'some-bucket-name',
        },
        files: [
          {
            expand: true,
            cwd: 'pages/',
            src: ['**'],
            dest: '/',
            differential: true,
            action: 'delete'
          }
        ],
      },
    },
  });

  grunt.loadNpmTasks('grunt-aws-s3');
  grunt.registerTask('deploy', [
    'aws_s3:dist',
  ]);
};
benblamey commented 8 years ago

I briefly attempted to debug the issue, and noticed the following in aws_s3.js gruntjs - cwd issue

i.e. the missing 'cwd' is present on the copy of the object in the 'orig' property, but not in the filepair itself?!

MathieuLoutre commented 8 years ago

Sorry! Only just seen this. Thanks for having a deeper look as well. Maybe this line should read filePair.differential && !filePair.orig.cwd? Can you try it that way. If it does work for you, I'm happy to take a PR or I can make the change if you prefer. Let me know!

benblamey commented 8 years ago

I tried the change as suggested - and I get a different error:

Running "aws_s3:dist" (aws_s3) task
Deleting the content of https://s3-eu-west-1.amazonaws.com/xxxxxx/
Fatal error: Path must be a string. Received undefined
ghost commented 8 years ago

Hello i see in README file that (delete: will only delete the files which don't exist locally) but no example how it work, can anyone tell me how ?

Thanks.

ghost commented 8 years ago

j'ai trouvé il fallait que je rajoute un / a dest et mettre differential: true et cwd dans les options.

Merci.

trioni commented 8 years ago

Any updates about this?

MathieuLoutre commented 8 years ago

@trioni do you have the same error as OP or something different?

trioni commented 8 years ago

@MathieuLoutre yes, this error Fatal error: Differential delete needs a "cwd".

Currently using npm-scripts and the aws cli to achieve the same thing:

AWS_PROFILE=myprofile aws s3 sync ./public/build-$npm_package_version s3://mybucket/public --delete --region some-region
parsingphase commented 7 years ago

Having tested a few ways it looks like slashes in dirs aren't to blame, but using expand:true where action is delete causes the problem.

Given that no src is needed where action = delete, does 'expand:true' do anything anyway?

ie, this works unless I uncomment the expand under the 'delete' section:

        dev: {
            options: {
                // differential: true,
            },
            files: [/* files key pairs */
                {
                    action: 'upload', // send any files not currently present on remote
                    expand: true,
                    cwd: staticRootDir,
                    src: [ 'v2/**/*.png', '!uploads/**', '!**/img-raw/**'], // one subdir for testing
                    dest: 'domain_com/d/static-testing/', /* s3 destination */
                    differential: true,
                    /* headers: {}   /* override headers */
                },
                {
                    action: 'delete', // remove any files not longer present locally
                    // expand: true,
                    // src: '**/*.png',
                    dest: 'domain_com/d/static-testing/', /* s3 destination */
                    differential: true,
                    cwd: staticRootDir,
                    /* headers: {}   /* override headers */
                }
            ]
        }

Note that the trailing '/' on dest in the delete block is critically important if you don't want to delete every single file in the bucket.