bool has_source_file_counterpart(void* file_name) { if (string_endswith((char*)file_name, ".c")) { return true; } if (file_exists(change_extension(file_name, ".c"))) { return true; } return false; }
/* * Load all replication slots from disk into memory at server startup. This * needs to be run before we start crash recovery. */ void StartupReplicationSlots(XLogRecPtr checkPointRedo) { DIR *replication_dir; struct dirent *replication_de; ereport(DEBUG1, (errmsg("starting up replication slots"))); /* restore all slots by iterating over all on-disk entries */ replication_dir = AllocateDir("pg_replslot"); while ((replication_de = ReadDir(replication_dir, "pg_replslot")) != NULL) { struct stat statbuf; char path[MAXPGPATH]; if (strcmp(replication_de->d_name, ".") == 0 || strcmp(replication_de->d_name, "..") == 0) continue; snprintf(path, MAXPGPATH, "pg_replslot/%s", replication_de->d_name); /* we're only creating directories here, skip if it's not our's */ if (lstat(path, &statbuf) == 0 && !S_ISDIR(statbuf.st_mode)) continue; /* we crashed while a slot was being setup or deleted, clean up */ if (string_endswith(replication_de->d_name, ".tmp")) { if (!rmtree(path, true)) { ereport(WARNING, (errcode_for_file_access(), errmsg("could not remove directory \"%s\"", path))); continue; } fsync_fname("pg_replslot", true); continue; } /* looks like a slot in a normal state, restore */ RestoreSlotFromDisk(replication_de->d_name); } FreeDir(replication_dir); /* currently no slots exist, we're done. */ if (max_replication_slots <= 0) return; /* Now that we have recovered all the data, compute replication xmin */ ReplicationSlotsComputeRequiredXmin(); ReplicationSlotsComputeRequiredLSN(); }
/** * @fn _Bool virtual_cache_can_cache(virtual_cache_t vc, cache_item_name_t name) * @brief Test if the current name is cacheable. * @param vc The virtual cache pointer. * @param name The name to test. * @return true/false. */ _Bool virtual_cache_can_cache(virtual_cache_t vc, cache_item_name_t name) { struct virtual_cache_s *v = (struct virtual_cache_s*)vc; if(!v) return false; _Bool ret = true; if(!strlen(v->resources_to_exclude)) return ret; stringtoken_t tokens = stringtoken_init(v->resources_to_exclude, ","); char* temp; while(stringtoken_has_more_tokens(tokens)) { temp = stringtoken_next_token(tokens); if(string_endswith(name, temp)) { free(temp); ret = false; break; } free(temp); } stringtoken_release(tokens); return ret; }
bool OSLRenderServices::texture(ustring filename, TextureOpt &options, OSL::ShaderGlobals *sg, float s, float t, float dsdx, float dtdx, float dsdy, float dtdy, float *result) { OSL::TextureSystem *ts = osl_ts; ShaderData *sd = (ShaderData *)(sg->renderstate); KernelGlobals *kg = sd->osl_globals; #ifdef WITH_PTEX /* todo: this is just a quick hack, only works with particular files and options */ if(string_endswith(filename.string(), ".ptx")) { float2 uv; int faceid; if(!primitive_ptex(kg, sd, &uv, &faceid)) return false; float u = uv.x; float v = uv.y; float dudx = 0.0f; float dvdx = 0.0f; float dudy = 0.0f; float dvdy = 0.0f; Ptex::String error; PtexPtr<PtexTexture> r(ptex_cache->get(filename.c_str(), error)); if(!r) { //std::cerr << error.c_str() << std::endl; return false; } bool mipmaplerp = false; float sharpness = 1.0f; PtexFilter::Options opts(PtexFilter::f_bicubic, mipmaplerp, sharpness); PtexPtr<PtexFilter> f(PtexFilter::getFilter(r, opts)); f->eval(result, options.firstchannel, options.nchannels, faceid, u, v, dudx, dvdx, dudy, dvdy); for(int c = r->numChannels(); c < options.nchannels; c++) result[c] = result[0]; return true; } #endif OSLThreadData *tdata = kg->osl_tdata; OIIO::TextureSystem::Perthread *thread_info = tdata->oiio_thread_info; OIIO::TextureSystem::TextureHandle *th = ts->get_texture_handle(filename, thread_info); bool status = ts->texture(th, thread_info, options, s, t, dsdx, dtdx, dsdy, dtdy, result); if(!status) { if(options.nchannels == 3 || options.nchannels == 4) { result[0] = 1.0f; result[1] = 0.0f; result[2] = 1.0f; if(options.nchannels == 4) result[3] = 1.0f; } } return status; }