Example #1
0
void SongCacheIndex::ReadCacheIndex()
{
    CacheIndex.ReadFile( CACHE_INDEX );	// don't care if this fails

    int iCacheVersion = -1;
    CacheIndex.GetValue( "Cache", "CacheVersion", iCacheVersion );
    if( iCacheVersion == FILE_CACHE_VERSION )
        return; /* OK */

    LOG->Trace( "Cache format is out of date.  Deleting all cache files." );
    EmptyDir( CACHE_DIR );
    EmptyDir( CACHE_DIR "Banners/" );
    EmptyDir( CACHE_DIR "Songs/" );

    CacheIndex.Reset();
}
Example #2
0
void MusicUtils::EmptyDir(CString Dir)
{
	CFileFind finder;
	CFile cfile;
	CString Add=L"\\*";
	CString DirSpec=Dir+Add;                        //????????????
	BOOL bWorking = finder.FindFile(DirSpec);


	while (bWorking)
	{
		bWorking = finder.FindNextFile();

		if(!finder.IsDots())              //????????
		{
			if(finder.IsDirectory())           //????????
			{
				CString strDirectory = finder.GetFilePath();
				if(_rmdir((const char*)(LPSTR)(LPCTSTR)strDirectory)==-1)
				{
					EmptyDir(strDirectory); 
				}
				bWorking = finder.FindFile(DirSpec);
			}
			else                               //???????
			{
				cfile.Remove(finder.GetFilePath());
			}
		}
	}
	finder.Close();

}
Example #3
0
File: fsrtns.c Project: juddy/edcde
static int
EraseObject(char *nameP, int force)
{
  struct stat src_stat;
  int rc = 0;

  if (periodicCallback)
    if (periodicCallback() != 0)
      return -1;

  if (lstat(nameP, &src_stat) < 0)
    rc = errno;
  else if ((src_stat.st_mode & S_IFMT) == S_IFDIR) {
    if (access(nameP, X_OK|W_OK))
      return errno;
    rc = EmptyDir(nameP, 1, force);
  }
  else {
    if (!force && access(nameP, W_OK))
      return errno;

    if (unlink(nameP))
      rc = errno;
  }

  /*
   * Return code zero means everything is ok;
   * return code -1 means the operation is aborted.
   * In either case, propagated the return code up.
   */
  if (rc <= 0)
    return rc;

  /*
   * Return code > 0 means an error occurred in the last operation.
   * Call the the error callback function.  If the callback returns
   * zero, we return zero; this will cause the error to be ignored.
   * Otherwise we return -1 to signal that the operation is aborted.
   */
  if (!errorCallback)
    return rc;
  else if (errorCallback(nameP, rc) == 0)
    return 0;
  else
    return -1;
}
Example #4
0
    void ClientSession::H_Read_File(const boost::system::error_code& error)
    {
        if(!error)
        {
            LOG(INFO)<< "ClientSession :: Read proto SUCCESSFUL " ;
            switch (_header_.type)
            {
                case SEARCH_REQUEST:
                    {
                        SearchProtoMessage search_proto_message;  
                        if(!search_proto_message.ParseFromArray(_proto_buf_ptr_,_header_.length))
                        {
                            LOG(ERROR)<< "ClientSession :: parse error ";

                            //g_session_manager->Recycle(GetSessionID());
                            return ;
                        }				
                        else
                        {
                            if(search_proto_message.retrain()== -1)
                            {
                        LOG(INFO)<< "ClientSession :: Proto show it is SEARCH_REQUEST " ;
                                if(_proto_buf_ptr_ != NULL)
                                {
                                    delete []_proto_buf_ptr_;
                                    _proto_buf_ptr_ = NULL;
                                }
                                //获取到picture的length				
                                _pic_len_ = search_proto_message.picture_length();
                                LOG(INFO)<< "ClientSession :: Proto shows : picture_length : "
                                    << _pic_len_  <<" picture name : "
                                    <<search_proto_message.picture_name();
                                if(_pic_len_ > 512000 )//设置接收的图片大小不超过500K
                                {
                                    LOG(ERROR)<< "ClientSession :: too large picture size ";
                                    /*
                                     *todo 
                                     *这时返回ROOT错误查询,让ROOT关闭此连接
                                     *
                                     * */
                                }
                                _content_buf_ptr_ = new char[ _pic_len_  ];
                                memset(_content_buf_ptr_ , 0 ,_pic_len_ );
                                _pic_len_ = search_proto_message.picture_length();
                                boost::asio::async_read(_socket_,
                                    boost::asio::buffer(_content_buf_ptr_,_pic_len_),
                                    boost::bind(&ClientSession::H_New_Search_Session, this,
                                        boost::asio::placeholders::error , search_proto_message , _content_buf_ptr_));	
                            }
                            else if(search_proto_message.retrain()== 1)
                            {
                        LOG(INFO)<< "ClientSession :: Proto show it is RETRAIN_REQUEST " ;
                                g_match_lock.lock();
                                remove(INDEXPATH);
                                EmptyDir(FEATUREPATH) ;
                                delete g_pic_matcher;
                                g_pic_matcher = new Matcher();
                                g_pic_matcher->train(TRANDIR, FEATUREPATH, INDEXPATH);
                                g_match_lock.unlock();
                                SearchResultMessage ack;
                                ack.set_status(0);
                                ack.set_retrain(1);
                                ack.set_mj_id("");
                                ack.set_task_id(0);
                                ack.set_picture_name("");
                                ack.set_result_length(0);
                                ack.set_trackerurl("");
                                string tmp;
                                ack.SerializeToString(&tmp);
                                HeadStructMessage header;
                                header.type = SEARCH_REQUEST_RESULT_FROM_NODE;
                                header.length = tmp.length();
                                string send((char *)&header , sizeof(HeadStructMessage));
                                send += tmp;
                                boost::asio::async_write(_socket_,
                                    boost::asio::buffer(send ,send.length()),
                                    boost::bind(&ClientSession::H_Read_Header, this,
                                        boost::asio::placeholders::error ));	
                            }
                        }
                        break; 
                    }
                    /*  
                case 0xa2:
                    {
                        LOG(INFO)<< "ClientSession :: Proto show it is TRAIN_REQUEST " ;
                        TrainPictureProtoMessage train_proto_message;  
                        if(!train_proto_message.ParseFromArray(_proto_buf_ptr_,_header_.length))
                        {
                            LOG(ERROR)<< "ClientSession :: train parse error ";
                            return ;
                        }				
                        else
                        {
                            if(_proto_buf_ptr_ != NULL)
                            {
                                delete []_proto_buf_ptr_;
                                _proto_buf_ptr_ = NULL;
                            }
                            g_match_lock.lock();
                            g_pic_matcher->train(TRANDIR, FEATUREPATH, INDEXPATH);
                            g_match_lock.unlock();
                            TrainPictureProtoMessageACK ack;
                            ack.set_session_id(train_proto_message.session_id());
                            ack.set_status(1);
                            string tmp;
                            ack.SerializeToString(&tmp);
                            HeadStructMessage header;
                            header.type = 0xa3;
                            header.length = tmp.length();
                            string send((char *)&header , sizeof(HeadStructMessage));
                            send += tmp;
                            boost::asio::async_write(_socket_,
                                boost::asio::buffer(send ,send.length()),
                                boost::bind(&ClientSession::H_Read_Header, this,
                                    boost::asio::placeholders::error ));	
                        }
                        break; 
                    }
                    */
                default : 
                    LOG(INFO)<< "ClientSession :: header.type not recongnize : " <<_header_.type;
                break;
            }
       ;}
        else
        {
        
        }
    
    }
Example #5
0
File: fsrtns.c Project: juddy/edcde
void
fsEmpty(char *nameP, int *rcP)
{
  *rcP = EmptyDir(nameP, 0, 0);
}