GithubHelp home page GithubHelp logo

cpr's People

Contributors

benelliott avatar benelliottgsa avatar brianloveswords avatar davglass avatar fresheneesz avatar jonnyreeves avatar jrpool avatar pdehaan avatar plutomatt avatar satazor avatar silverwind avatar soyuka avatar stevenvachon avatar tmpvar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

cpr's Issues

Option for symlink resolving

Hello!

Thank you for taking your time to implement this useful module.

However, does it support symlink resolving as ncp does? I can't find it in the documentation.

Thank you!

Intermittent file not done piping

Given a file named "changed.txt" with the contents:

changed-v1

And with the following code added to the copyFile function:

            fromFile.on('error', onError);
            toFile.on('error', onError);
            fromFile.once('end', function() {
                cb(err);
                if (to === 'changed.txt') {
                  console.error(to);
                  console.error(fs.readFileSync(from, 'utf8'));
                  console.error(fs.readFileSync(to, 'utf8'));
                }
            });
            fromFile.pipe(toFile);

About 50% of the time I get in the console:

changed.txt
changed-v1

changed-v1

And the other 50% I get:

changed.txt
changed-v1


It seems like there may be a race condition in the piping and "end" event. I should also note that there are other files in the operation, and this is the only one affected. For instance using fixturify:

{ 'changed.txt': '',
  'missing-changed.txt': 'changed-v1\n',
  'missing-unchanged.txt': 'unchanged\n',
  'removed-changed.txt': 'changed-v1\n',
  'removed-unchanged.txt': 'unchanged\n',
  'unchanged.txt': 'unchanged\n' }

Copy only changed files

Hello!

I have a project with extremely big directories. It would be a tremendous improvement if cpr would be able to compare files from source and target directory using timestamp and/or filesize.

Thanks!

Does not behave like cp -R when copying a single file

Hi,

I had assumed that this module would behave like the command it takes its name from, but it appears it does not do so when copying single files.

Say you have this file structure:

foo/
 `-- bar.jpg
baz/

and you want to copy foo/bar.jpg to baz/qux.jpg.

When you execute cp -R foo/bar.jpg baz/qux.jpg in command line, it creates a renamed copy to the target path. You get:

foo/
 `-- bar.jpg
baz/
 `-- qux.jpg

When using this project, on the other hand, you get:

foo/
 `-- bar.jpg
baz/
 `-- qux.jpg/
      `-- bar.jpg

I was relying on this behavior to have a generic purpose file copy module.

Colors as rgb() cannot be used for hover option anymore

Hi,

this issue appeared after update from 5.0.12 to 5.0.13 (as we actually trusted in semantic versioning). We are relying on that configuration option to set a different color for plotOptions/column/states/hover to show a semi transparent color on top of the actual gradient column fill color.

Since v5.0.13 we experienced a black fill color with a style value set to rgb(NaN, NaN, NaN) in DOM explorer when hovering.

I prepared a simplified demo here: https://jsfiddle.net/zt4xm146/ If you enable the showBug option in the 1st line you can simulate the issue by hovering the column bars.

The problem is - as far as we figured out: when using rgb() or rgba() string values for this option it results in that black filling.

How it worked before

Furthermore, try to replace the <script> tag in the HTML section to use 5.0.12 version of highcharts:
<script src="https://code.highcharts.com/5.0.12/highcharts.js"></script>

Now the bug toggle variable shows no effect in terms of black filling on hover.

Side note

I think it may be related to this new "Added color animation on state change for non-marker based series like columns and tree maps" feature I saw in the changelog for v5.0.13.

I wonder why such features show up in a patch version? ;-)

noJunk option

to exclude junk files (such as .DS_Store). This could be made available to the CLI and would reduce project dependencies.

overwrite:true removes dirs if they exist

Hey,

cpr removes dirs if they already exist, if overwrite:true is specified in options (which I assumed was just the same as -f).

So for a test.js which contains this:

var cpr = require('cpr');

cpr('build/', 'deployments/', {
    deleteFirst: false,
    overwrite: true,
    confirm: false
}, function(err, files) {
    if(err) {
        console.error('ERROR', err);
        return;
    }

    console.log('SUCCESS');
});

I see this behavior:

% find build             
build
build/assets
build/assets/2

% find deployments
deployments
deployments/assets
deployments/assets/1

% node test.js
SUCCESS

% find deployments/         
deployments/
deployments/assets
deployments/assets/2

whereas cp -R -f does the following:

% find build 
build
build/assets
build/assets/2

% find deployments 
deployments
deployments/assets
deployments/assets/1

% cp -R build/* deployments 
% find deployments
deployments
deployments/assets
deployments/assets/1
deployments/assets/2

and without overwrite: true it fails on the already existing assets/ dir (and possibly other already existing files). So right now there seems to be no way to merge to directory trees with cpr. ... or am I overlooking anything?

AFAICT this is the code causing this behavior: https://github.com/davglass/cpr/blob/master/lib/index.js#L113

Why was that code added in the first place?

BR,
Domme

regex in filter option not working as expected with directories.

Greetings! I have the following code that is trying to ignore CVS directories, but the last 5 variations of regex I tried do not appear to work as expected, but I've tested the regex online and in other code, so the format should be ok. Any tips on what I might be doing wrong are appreciated.

` code snippet

cpr('./public', 'build/public/', {
  deleteFirst: true,
  overwrite: true,
  confirm: true,
  filter: '^((?!CVS).)*$'
}, function (err) {
 if (err) {
  console.log(colors.red.bold('Something went wrong during copy: '), err.stack);
  return console.error(err);
 }
 console.log(colors.blue.bold('...copied ./public to build directory!'));
});

`

silent option

To suppress errors if the source did not exist (ENOENT). Errors should still be thrown if the user's permissions were insufficient.

Update mkdirp dependency

Hi,

this patch looks enough to update mkdirp dependency to ^1.0.3:

--- a/lib/index.js                                                                                
+++ b/lib/index.js                                                                                
@@ -121,12 +121,12 @@                                                                             
                     err.errno = 27;                                                              
                     options.errors.push(err);                                                    
                 } else {                                                                         
-                    mkdirp(to, stat.mode, stack.add(function(err) {                              
+                    mkdirp(to, stat.mode).catch((err) => {stack.add(function(err) {              
                         /*istanbul ignore next*/                                                 
                         if (err) {                                                               
                             options.errors.push(err);                                            
                         }                                                                        
-                    }));                                                                         
+                    })});                                                                        
                 }                                                                                
             }));                                                                                 
         }                                                                                        
@@ -139,7 +139,7 @@                                                                               
                                                                                                  
 var copyFile = function(from, to, options, callback) {                                           
     var dir = path.dirname(to);                                                                  
-    mkdirp(dir, function() {                                                                     
+    mkdirp(dir).then( () => {                                                                    
         fs.stat(to, function(statError) {                                                        
             var err;                                                                             
             if(!statError && options.overwrite !== true) {                                       

Please add a CLI

It would be great if cpr included a CLI. This would make it super easy to write scripts that work across Linux, Mac, and Windows. Something like this:

cpr [source_dir] [destination_dir]

And if you want to be really awesome, you could support multiple source files and/or globs:

cpr [source_file1] [source_file2] [...source_fileN] [destination_dir]

cpr [source_glob] [destination_dir]

Callback not fired if we don't have write permissions for the destination

You can observe this by adding the following test to tests/full.js:

    "should fail without write permissions": {
        topic: function() {
            var self = this;
            var mkdirp = require('mkdirp');
            var baddir = path.join(to, 'readonly');
            mkdirp.sync(baddir);
            fs.chmodSync(baddir, '555');
            cpr(from, baddir, function(err,status) {
                self.callback(null, {
                    err: err,
                    status: status
                });
            });
        },
        "should return an error in the callback": function(topic) {
            assert.isUndefined(topic.status);
            assert(topic.err instanceof Error);
            //assert.equal('From should be a file or directory', topic.err.message);
        }
    },

npm test outputs:

✗ Errored » callback not fired
      in should fail without write permissions
      in CPR Tests
      in tests/full.js
✗ Errored » 38 honored ∙ 1 errored ∙ 1 dropped

npm ERR! Test failed.  See above for more details.

Globs

cpr("/path/to/dir/", "/dest/")
//-> copies contents of /path/to/dir/ into /dest/

cpr("/path/to/dir/**/*", "/dest/")
//-> same as above

cpr("/path/**/dir/", "/dest/")
//-> same, and possibly more if there're other nested dirs named "dir"

When/if glob expands directories, we can use glob.Glob to copy each file as it is expanded from the glob. This is not only better because it helps avoid race conditions by copying the file immediately after it's expanded, but it may also have better performance because the hard drive has already sought to that track/sector.

Since a glob will likely resolve to many files, we might as well implement #41 along with this. An instance of glob.Glob per glob and file paths memoized to avoid redundancy.

cpr(["/path/to/dir/", "/path/to/dir/**/*", "/path/**/dir/"], "/dest/")
//-> same as above, with no file copied more than once

CLI options?

It is possible to pass the API options as arguments to the CLI interface? E.g. cpr --overwrite foo bar

Filtering of items

Trying to filter the list of items to not include anything that is hidden ex: ._helloFile or ._helloWorld.jpg

Seems to not be working correctly AND the files array that is passed to the callback still returns everything in the source folder rather than my filtered results. What am I doing wrong?

    cpr(source, destination, {
      //deleteFirst: true, //Delete "to" before
      overwrite: true, //If the file exists, overwrite it
      confirm: true, //After the copy, stat all the copied files to make sure they are there
      filter:/^(^[_].*)*$/gmi
  }, function(err, files) {
      if(err){
        console.log(err)
        _self.logs = err;
      
      }else{
        console.log(files)
 
      }
    
  });

cp -a

preserve links and attributes

Not particularly useful to me, at least right now, but it might be a good goal to reach.

Copy failed with EACCES if directory in source dirs has no write permissions

How to reproduce:

  1. Create file structure like this:
mkdir -p src/bar # create nested folders
touch src/bar/test.txt # create file
chmod -w -R src # revoke write permissions
  1. Try to copy src folder with cpr:
const cpr = require('cpr')
cpr('src', 'dest', (err, res) => { if (err) throw err; console.log(res) })

It will produce this error:

Uncaught [Error: Unable to copy directory entirely] {
  list: [
    [Error: EACCES: permission denied, mkdir '/path/to/dest/bar'] {
      errno: -13,
      code: 'EACCES',
      syscall: 'mkdir',
      path: '/path/to/dest/bar'
    },
    [Error: ENOENT: no such file or directory, open 'dest/bar/test.txt'] {
      errno: -2,
      code: 'ENOENT',
      syscall: 'open',
      path: 'dest/bar/test.txt'
    }
  ]
}

I expect behaviour as original cp command has:

cp -R src dest # success
ls -l dest
total 0
dr-xr-xr-x  3 isqua isqua 102 Oct 30 22:53 ./
drwxr-xr-x 19 isqua isqua 646 Oct 30 22:53 ../
dr-xr-xr-x  3 isqua isqua 102 Oct 30 22:53 bar/
ll dest/bar
total 0
dr-xr-xr-x 3 isqua isqua 102 Oct 30 22:53 ./
dr-xr-xr-x 3 isqua isqua 102 Oct 30 22:53 ../
-r--r--r-- 1 isqua isqua   0 Oct 30 22:53 test.txt

NodeJS version: v12.18.1
cpr version: 3.0.1, 2.2.0

Error: Unable to copy directory entirely

Using cpr v1.0.0, I get the error Unable to copy directory entirely when i try to use CPR to copy directories in a linux centos environment. Things were working fine when I was using 0.4.2, so I'm just going to switch back to that.

Empty directory handling

Seems this module doesn't handle empty directories very well. Given a file tree

parent
    child-dir
    child.file

If you cpr the parent somewhere, there's an inevitable stat error on the destination child-dir path. Similary, just running cpr on an empty directory also fails. I'm working around this now with

fs.readdir(src, function (err, files) {
    if (files.length) {
        cpr(src, dst, function (errs) {
            if (!errs) return;
            errs.forEach(function (err) {
                if (err.code === "ENOENT" && err.syscall === "stat") {
                    mkdirp(err.path);
                }
            });
        });
    } else {
        mkdirp(dst);
    }
});

but it'd be nice to see this fixed :)

Thank you!

I was having a difficult time filtering out files with node ncp from npm, because negating a regex in JS is generally hard, but with cpr filtering excludes files instead of including them, which is a nice default.

Funny logo. :)

files array in callback not populated when confirm is true

cpr('./mockData/', './results/', {
        confirm: true
}, function (err, files) {
        if (err) {
                return console.error('can not do it', err);
        }
        files.forEach(function (file) {
                console.log('copied: ', file);
        });
});

//No output, files is an empty array

No errno codes

cpr("source", "destination", function(error) {
    console.log(error.code);
    //-> undefined
});

I was expecting something like "EEXIST".

Errors normalization

From what I read from the source code, the errors can actually be a string or an array of strings, which I found very odd from a consumer perspective.

I would suggest to normalize this to always be an array of Error instances. Unlike strings, error instances gives more information about the actual error. For instance, we can get a stack trace from it if necessary.

If you guys agree with this, I will make a PR with these changes. This is an API change which translates in a major release bump.

IO throttling.

Hey, I'm curious if interest exists in introducing some throttling on IO, this would be to prevent overwhelming the system when copying large trees.

Or maybe a recommendation for preventing this. I realize the synchronize variant (not yet merged) would likely not have this issue.

Missing change log

I am unable to find a change log for this project anywhere. It would be good to know what changed between all those releases and the major ones with potentially breaking changes in particular.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.