def delete(self, uid): try: remove(self.store_dir + uid) except FileNotFoundError: return response.build_not_found_error() return response.build_successful({})
def _put_handler(self, header, body): uid, error = self._get_item_id(header["path"], header["method"]) if (error != None): return res.buid_id_error(error) response, status = self.cache.update(uid, body) # cache is zero size, then directly # store the new data, it could return an # error message if there were no such file if (status == res.CACHE_ZERO_SIZE_STATUS): return self.fs.put(uid, body) # the item was not in the cache if (status == res.NOT_FOUND_STATUS): if not self.fs.check(uid): return res.build_not_found_error() # store the update of the item with # the flag 'in_disc' turn on because # there is a copy of it in disc self._store_item(uid, body, 1) return res.build_successful({})
def put(self, uid, data): try: with open(self.store_dir + uid, "r+") as f: json.dump(data, f) except FileNotFoundError: return response.build_not_found_error() return response.build_successful({})
def get(self, uid): try: with open(self.store_dir + uid, "r") as f: data = json.load(f) except FileNotFoundError: return response.build_not_found_error() return response.build_successful(data)
def get(self, uid): if uid not in self.data: return response.build_not_found_error() item = self.data[uid] self.data[uid] = (item[0], item[1] + 1, item[2]) return response.build_successful(self.data[uid][0])
def update(self, uid, data): if (self.size == 0): return response.build_cache_zero_error("") if uid not in self.data: return response.build_not_found_error() item = self.data[uid] self.data[uid] = (data, item[1] + 1, item[2]) return response.build_successful("")
def delete(self, uid): if uid not in self.data: return response.build_not_found_error() is_in_disc = self.data[uid][2] del self.data[uid] if (self.count > 0): self.count -= 1 if (is_in_disc): return response.build_in_disc_error("") return response.build_successful("")