emscripten Humble Cloud interface
Edward Rudd
2014-08-30 53d00e8ba099980f1945c045c5fe0767cdb7b5a3

implement removing of deleted files in the cloud

1 files modified
38 ■■■■ changed files
client/library/library_cloudfs.js 38 ●●●● patch | view | raw | blame | history
client/library/library_cloudfs.js
@@ -46,7 +46,7 @@
              total++;
            }
          });
          /*
          var remove = [];
          Object.keys(dst.entries).forEach(function (key) {
            var e = dst.entries[key];
@@ -56,7 +56,7 @@
              total++;
            }
          });
          */
          if (!total) {
            return callback(null);
          }
@@ -93,16 +93,13 @@
            }
          });
          return;
          // sort paths in descending order so files are deleted before their
          // parent directories
          remove.sort().reverse().forEach(function(path) {
            var info = dst.entries[path];
            if (dst.type === 'local') {
              CLOUDFS.removeLocalEntry(path, info, done);
              CLOUDFS.removeLocalEntry(path, done);
            } else {
              CLOUDFS.removeRemoteEntry(path, info, done);
              CLOUDFS.removeRemoteEntry(mount, dst.entries[path], done);
            }
          });
        },
@@ -276,6 +273,33 @@
                    callback(e);
                })
            }
        },
        // remove local and remote files
        removeLocalEntry: function(path, callback) {
          try {
            var lookup = FS.lookupPath(path);
            var stat = FS.stat(path);
            if (FS.isDir(stat.mode)) {
              FS.rmdir(path);
            } else if (FS.isFile(stat.mode)) {
              FS.unlink(path);
            }
          } catch (e) {
            return callback(e);
          }
          callback(null);
        },
        removeRemoteEntry: function(mount, pathinfo, callback) {
          if (pathinfo.type == 'file') {
            mount.opts.provider.rm(mount.opts.cloud, pathinfo, function() {
              callback(null);
            },
            function(e) {
              callback(e);
            });
          }
        }
    }
};