q-io copyTree and "mergeTree"

23 views
Skip to first unread message

Bruce Cartland

unread,
Nov 12, 2013, 5:05:44 PM11/12/13
to q-con...@googlegroups.com
The CommonJS/Fileystem/A spec is vague about various behaviour (unless there's standard expected behaviour I'm not aware of), but having copyTree() fail because makeDirectory() fails due to an existing target directory, seems unfortunate and inconsistent with the behavior at the file level, which just overwrites existing target files (as long as they're writable).

Can this be changed to allow for existing target directories?

Alternatively, how about an additional method "mergeTree()" ?

  exports.mergeTree = function(source, target) {
    var self = this;
    return Q.when(self.stat(source), function(stat) {
      if (stat.isFile()) {
        return self.copy(source, target);
      } else if (stat.isDirectory()) {
        return self.exists(target).then(function(dstExists) {
          var mergeSubTree = Q.when(self.list(source), function(list) {
            return Q.all(list.map(function(child) {
              return self.mergeTree(self.join(source, child), self.join(target, child));
            }));
          });
          if (dstExists) {
            return mergeSubTree;
          } else {
            return Q.when(self.makeDirectory(target), function() {
              return mergeSubTree;
            });
          }
        });
      } else if (stat.isSymbolicLink()) {
        return self.symbolicCopy(source, target);
      }
    });
  };

thanks

Kris Kowal

unread,
Nov 12, 2013, 5:19:46 PM11/12/13
to Q Continuum
I’m amenable to both ideas.

Bruce Cartland

unread,
Nov 12, 2013, 6:05:13 PM11/12/13
to q-con...@googlegroups.com
Great. Then I'd vote for changing copyTree().

Will you do this or I do and submit a pull request??

Kris Kowal

unread,
Nov 12, 2013, 6:08:45 PM11/12/13
to Q Continuum
If you could make an issue ticket first, we might get more feedback and opinions there. I would not want to waste your time. Aside from that, I am always ecstatic to receive pull requests. I never have enough time and always can use help.

Bruce Cartland

unread,
Nov 12, 2013, 6:18:27 PM11/12/13
to q-con...@googlegroups.com
Will do.

thanks
Reply all
Reply to author
Forward
0 new messages