Exemplo n.º 1
0
 void setCacheableFile(const FilePath& filePath, 
                       const Request& request, 
                       const Filter& filter)
 {
    // ensure that the file exists
    if (!filePath.exists())
    {
       setError(http::status::NotFound, request.uri() + " not found");
       return;
    }
    
    // set Last-Modified
    using namespace boost::posix_time;
    ptime lastModifiedDate = from_time_t(filePath.lastWriteTime());
    setHeader("Last-Modified", util::httpDate(lastModifiedDate));
    
    // compare file modified time to If-Modified-Since
    if (lastModifiedDate == request.ifModifiedSince())
    {
       removeHeader("Content-Type"); // upstream code may have set this
       setStatusCode(status::NotModified);
    }
    else
    {
       setFile(filePath, request, filter);
    }
 }
Exemplo n.º 2
0
FilePath projectFromDirectory(const FilePath& directoryPath)
{
   // first use simple heuristic of a case sentitive match between
   // directory name and project file name
   FilePath projectFile = directoryPath.childPath(
                                       directoryPath.filename() + ".Rproj");
   if (projectFile.exists())
      return projectFile;

   // didn't satisfy it with simple check so do scan of directory
   std::vector<FilePath> children;
   Error error = directoryPath.children(&children);
   if (error)
   {
      LOG_ERROR(error);
      return FilePath();
   }

   // build a vector of children with .rproj extensions. at the same
   // time allow for a case insensitive match with dir name and return that
   std::string projFileLower = string_utils::toLower(projectFile.filename());
   std::vector<FilePath> rprojFiles;
   for (std::vector<FilePath>::const_iterator it = children.begin();
        it != children.end();
        ++it)
   {
      if (!it->isDirectory() && (it->extensionLowerCase() == ".rproj"))
      {
         if (string_utils::toLower(it->filename()) == projFileLower)
            return *it;
         else
            rprojFiles.push_back(*it);
      }
   }

   // if we found only one rproj file then return it
   if (rprojFiles.size() == 1)
   {
      return rprojFiles.at(0);
   }
   // more than one, take most recent
   else if (rprojFiles.size() > 1 )
   {
      projectFile = rprojFiles.at(0);
      for (std::vector<FilePath>::const_iterator it = rprojFiles.begin();
           it != rprojFiles.end();
           ++it)
      {
         if (it->lastWriteTime() > projectFile.lastWriteTime())
            projectFile = *it;
      }

      return projectFile;
   }
   // didn't find one
   else
   {
      return FilePath();
   }
}
Exemplo n.º 3
0
void SourceManager::recordSourcedFile(const FilePath& filePath, bool local)
{
   SourcedFileInfo fileInfo(filePath.lastWriteTime(), local); 
   sourcedFiles_[filePath.absolutePath()] = fileInfo ;
}