log.debug(" Cleaned up %s..." % path)
+ async def rmtree(self, path):
+ """
+ Removes a directory recursively
+ """
+ # Normalize the path
+ path = os.path.abspath(path)
+
+ # Check if the path is within our base directory
+ if not path.startswith(self.basepath):
+ raise OSError("Cannot delete %s which is outside %s" % (path, self.basepath))
+
+ log.debug("Removing %s..." % path)
+
+ await asyncio.to_thread(shutil.rmtree, path)
+
def tempfile(self, mode="w+b", delete=True):
"""
Returns an open file handle to a new temporary file
# Move the new repository data to its destination
shutil.move(t, path)
+
+ # Delete
+
+ async def delete(self, user=None):
+ """
+ Deletes this repository
+ """
+ # Mark as deleted
+ self._set_attribute_now("deleted_at")
+ if user:
+ self._set_attribute("deleted_by", user)
+
+ # Local path
+ path = self.local_path()
+
+ # Lock the repository and remove all files
+ async with self.lock:
+ await self.backend.rmtree(path)
priority integer,
owner_id integer,
created_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
- listed boolean DEFAULT true NOT NULL
+ listed boolean DEFAULT true NOT NULL,
+ deleted_by integer
);
ADD CONSTRAINT repo_builds_repo_id FOREIGN KEY (repo_id) REFERENCES public.repositories(id);
+--
+-- Name: repositories repositories_deleted_by; Type: FK CONSTRAINT; Schema: public; Owner: -
+--
+
+ALTER TABLE ONLY public.repositories
+ ADD CONSTRAINT repositories_deleted_by FOREIGN KEY (deleted_by) REFERENCES public.users(id);
+
+
--
-- Name: repositories repositories_distro_id; Type: FK CONSTRAINT; Schema: public; Owner: -
--