TODO: refactor, abstract delete storage logic
175139
def update_and_delete_storage(node, key, value)
      old_node = node.dup
      new_node = update_node(node, key, value)
      delete_node_storage(old_node) if old_node != new_node
      new_node
    end
814700
Delta newDeleteStorage(Storage storage) {
        return Deltas.mapBuilder()
                .update(STORAGE.key(), Deltas.mapBuilder()
                        .remove(storage.getUuidString())
                        .deleteIfEmpty()
                        .build())
                .deleteIfEmpty()
                .build();
    }
1319413
function ExpiredStorage(storage) {

        // set default storage to localStorage
        storage = storage || (typeof localStorage !== "undefined" ? localStorage : null);

        // sanity check1: make sure we have a valid storage class to use.
        if (!storage) {
            throw new Error("ExpiredStorage: No storage base class provided and 'localStorage' is undefined! Please provide a valid base storage class.");
        }

        // sanity check2: make sure the storage class provide the required API.
        if (!(storage.setItem && storage.getItem && storage.removeItem && storage.clear)) {
            throw new Error("ExpiredStorage: Storage class  don't support one or more of the required API functions: getItem, setItem, removeItem or clear.");
        }

        // set storage class
        this._storage = storage;
    }
56675
function(attrs, attrsToRemove) {
    _.forEach(attrs, function(val, key) {
      // shouldRemove is either an object or a boolean
      var shouldRemove = attrsToRemove[key];
      if (_.isUndefined(shouldRemove)) {
        return;
      }

      // Support nested object
      if (_.isPlainObject(val) && !_.isArray(val) && _.isPlainObject(shouldRemove)) {
        return this._removeAttributes(val, shouldRemove);
      }

      if (shouldRemove) {
        delete attrs[key];
      }
    }.bind(this));
  }
257042
function _cleanObject (memo, value, key) {
  if (_hasData(value)) {
    memo[key] = value._data.data;
  } else if (_.isArray(value)) {
    memo[key] = _.reduce(value, _cleanArray, []);
  } else {
    memo[key] = value;
  }
  return memo;
}
1076953
private void deleteFiles(Predicate<File> predicate) {
    directory.mkdirs();

    // Iterate through all files in the storage directory.
    for (File file : directory.listFiles(f -> f.isFile() && predicate.test(f))) {
      try {
        Files.delete(file.toPath());
      } catch (IOException e) {
        // Ignore the exception.
      }
    }
  }
284400
function(callback) {

            // first check if storage define a 'keys()' function. if it does, use it
            if (typeof this._storage.keys === "function") {
                var keys = this._storage.keys();
                for (var i = 0; i < keys.length; ++i) {
                    callback(keys[i]);
                }
            }

            // if not supported try to use object.keys
            else if (typeof Object === "function" && Object.keys) {
                var keys = Object.keys(this._storage);
                for (var i = 0; i < keys.length; ++i) {
                    callback(keys[i]);
                }
            }

            // if not supported try to use iteration via length
            else if (this._storage.length !== undefined && typeof this._storage.key === "function") {

                // first build keys array, so this function will be delete-safe (eg if callback remove keys it won't cause problems due to index change)
                var keys = [];
                for (var i = 0, len = this._storage.length; i < len; ++i) {
                    keys.push(this._storage.key(i));
                }
                // now actually iterate keys
                for (var i = 0; i < keys.length; ++i) {
                    callback(keys[i]);
                }
            }

            // if both methods above didn't work, iterate on all keys in storage class hoping for the best..
            else {
                for (var storageKey in this._storage) {
                    callback(storageKey);
                }
            }
        }
224670
function storage(key, val, cb) {
  var length = arguments.length;
  if (type(arguments[length - 1]) != 'function') length += 1;

  switch (length) {
    case 3: return val === null
      ? del(key, cb)
      : set(key, val, cb);
    case 2: return type(key) == 'object'
      ? set(key, val)
      : get(key, val);
    default:
      return count(key);
  }
}
1018542
@Override
    public Object beforeDelete(S storable) throws PersistException {
        S existing = (S) storable.copy();
        try {
            if (!existing.tryLoad()) {
                existing = null;
            }
            return existing;
        } catch (FetchException e) {
            throw e.toPersistException();
        }
    }
347393
private boolean cleanLockedObjects( LockedObject lo,
                                        boolean temporary ) {

        if (lo.children == null) {
            if (lo.owner == null) {
                if (temporary) {
                    lo.removeTempLockedObject();
                } else {
                    lo.removeLockedObject();
                }

                return true;
            }
            return false;
        }
        boolean canDelete = true;
        int limit = lo.children.length;
        for (int i = 0; i < limit; i++) {
            if (!cleanLockedObjects(lo.children[i], temporary)) {
                canDelete = false;
            } else {

                // because the deleting shifts the array
                i--;
                limit--;
            }
        }
        if (canDelete) {
            if (lo.owner == null) {
                if (temporary) {
                    lo.removeTempLockedObject();
                } else {
                    lo.removeLockedObject();
                }
                return true;
            }
            return false;
        }
        return false;
    }
910612
function store(key, value){
  var length = arguments.length;
  if (0 == length) return all();
  if (2 <= length) return set(key, value);
  if (1 != length) return;
  if (null == key) return storage.clear();
  if ('string' == typeof key) return get(key);
  if ('object' == typeof key) return each(key, set);
}
927915
function clear() {
  // TODO: Only remove used items
  data = {};
  if (localExists()) {
    try {
      // Clear session storage
      window.sessionStorage.clear();
    } catch (error) {
      _logger2.default.warn({
        description: 'Session storage could not be cleared.', error: error,
        obj: 'storage', func: 'removeItem'
      });
    }
  }
}
201173
function(api, id, key) {
  // get storage object
  var obj = _getStorageObject(api, id);
  if(obj !== null && key in obj) {
    // remove key
    delete obj[key];

    // see if entry has no keys remaining
    var empty = true;
    for(var prop in obj) {
      empty = false;
      break;
    }
    if(empty) {
      // remove entry entirely if no keys are left
      obj = null;
    }

    // set storage object
    _setStorageObject(api, id, obj);
  }
}
569016
function clearObject (obj, defs, assigns) {
  if (obj) {
    var len
    var isDefs = arguments.length > 1 && (defs === null || !isObject(defs))
    var extds = isDefs ? assigns : defs
    if (isPlainObject(obj)) {
      objectEach(obj, isDefs ? function (val, key) {
        obj[key] = defs
      } : function (val, key) {
        deleteProperty(obj, key)
      })
      if (extds) {
        objectAssign(obj, extds)
      }
    } else if (isArray(obj)) {
      if (isDefs) {
        len = obj.length
        while (len > 0) {
          len--
          obj[len] = defs
        }
      } else {
        obj.length = 0
      }
      if (extds) {
        obj.push.apply(obj, extds)
      }
    }
  }
  return obj
}
753052
public void delete() {
    try {
      Files.deleteIfExists(file.file().toPath());
    } catch (IOException e) {
      throw new StorageException(e);
    }
  }
1164135
function del(keys, cb){
  if(!keys || keys.length<=0){
    if(cb) return cb(new Error('empty key'));
    else throw new Error('empty key');
  }
  var fns = [];
  for(var j in this._stores){
    var store = this._stores[j];
    fns.push(store.del.bind(store, keys));
  }
  if(cb){
    concurrent(fns, cb);
  }else{
    var fiber = fibext(), rbw = false;
    concurrent(fns, function(){
      fiber.resume.apply(fiber, arguments);
      rbw = true;
    });
    rbw || fiber.wait();
  }
}
793140
def _storage_purge_all(delete=False, verbosity=0):
    """"""
    orphaned_storages = Storage.objects.filter(data=None)

    if verbosity >= 1:
        if orphaned_storages.exists():
            logger.info(__("Unreferenced storages ({}):", orphaned_storages.count()))
            for storage_id in orphaned_storages.values_list('id', flat=True):
                logger.info(__("  {}", storage_id))
        else:
            logger.info("No unreferenced storages")

    if delete:
        orphaned_storages.delete()