int File_remove(File *self) { int result; Datum *cmd = Datum_newWithCString_("rm "); Datum_append_(cmd, self->path); result = File_System(cmd); Datum_free(cmd); return result; }
int File_createDirectory(File *self) { int result; Datum *cmd = Datum_newWithCString_("mkdir -p "); Datum_append_(cmd, self->path); result = File_System(cmd); Datum_free(cmd); return result; }
int File_symbolicallyLinkTo_(File *self, File *other) { int result; Datum *cmd = Datum_newWithCString_("ln -sf "); Datum_append_(cmd, self->path); Datum_appendCString_(cmd, " "); Datum_append_(cmd, File_path(other)); result = File_System(cmd); Datum_free(cmd); return result; }
int File_copyTo_(File *self, File *other) { int result; Datum *cmd = Datum_newWithCString_("cp "); Datum_append_(cmd, self->path); Datum_appendCString_(cmd, " "); Datum_append_(cmd, File_path(other)); result = File_System(cmd); Datum_free(cmd); return result; }
int VertexServer_api_queueExpireTo(VertexServer *self) { PNode *fromNode = PDB_allocNode(self->pdb); PNode *toNode = PDB_allocNode(self->pdb); PNode *itemNode = PDB_allocNode(self->pdb); Datum *toPath = HttpRequest_queryValue_(self->httpRequest, "toPath"); unsigned int itemsExpired = 0; if (PNode_moveToPathIfExists_(fromNode, HttpRequest_uriPath(self->httpRequest)) != 0) { VertexServer_setErrorCString_(self, "from path does not exist: "); VertexServer_appendError_(self, HttpRequest_uriPath(self->httpRequest)); return -1; } //PNode_moveToPath_(toNode, toPath); if (PNode_moveToPathIfExists_(toNode, toPath) != 0) { VertexServer_setErrorCString_(self, "to path does not exist: "); VertexServer_appendError_(self, toPath); return -1; } PNode_first(fromNode); { Datum *qTimeKey = Datum_newWithCString_("_qtime"); Datum *k; Datum *qExpireKey = Datum_newWithCString_("_qexpire"); long now = time(NULL); while (k = PNode_key(fromNode)) { Datum *pid = PNode_value(fromNode); Datum *qExpireValue; PNode_setPid_(itemNode, pid); qExpireValue = PNode_at_(itemNode, qExpireKey); if(!qExpireValue) { Log_Printf("WARNING: attempt to expire a node with no _qexpire value\n"); if(PNode_at_(itemNode, qTimeKey) == 0x0) { Log_Printf("WARNING: node also missing _qtime value\n"); } break; } if(qExpireValue == 0x0 || Datum_asLong(qExpireValue) < now) { PNode_removeAtCursor(fromNode); // the remove will go to the next item PNode_key(fromNode); PNode_removeAt_(itemNode, qTimeKey); PNode_removeAt_(itemNode, qExpireKey); PNode_atPut_(toNode, k, pid); PNode_jumpToCurrentKey(fromNode); itemsExpired ++; } else { PNode_next(fromNode); } } Datum_free(qTimeKey); Datum_free(qExpireKey); } yajl_gen_integer(self->yajl, (long)itemsExpired); Datum_appendYajl_(self->result, self->yajl); return 0; }