2012-05-16 18:35:22 +04:00
|
|
|
/*
|
|
|
|
grive: an GPL program to sync a local directory with Google Drive
|
|
|
|
Copyright (C) 2012 Wan Wai Ho
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation version 2
|
|
|
|
of the License.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2012-05-19 14:03:02 +04:00
|
|
|
#include "ResourceTree.hh"
|
2012-05-29 21:30:06 +04:00
|
|
|
|
|
|
|
#include "util/DateTime.hh"
|
2012-05-16 20:52:17 +04:00
|
|
|
#include "util/FileSystem.hh"
|
2016-01-01 02:27:21 +03:00
|
|
|
#include "json/Val.hh"
|
2012-05-16 18:35:22 +04:00
|
|
|
|
2012-05-16 20:52:17 +04:00
|
|
|
#include <memory>
|
2015-09-25 13:01:26 +03:00
|
|
|
#include <boost/regex.hpp>
|
2012-05-16 18:35:22 +04:00
|
|
|
|
|
|
|
namespace gr {
|
|
|
|
|
2015-05-16 21:10:38 +03:00
|
|
|
class Entry ;
|
|
|
|
|
2015-05-17 02:00:00 +03:00
|
|
|
class Syncer ;
|
2013-04-29 09:23:34 +04:00
|
|
|
|
2012-05-19 11:41:21 +04:00
|
|
|
class Resource ;
|
2012-05-16 18:35:22 +04:00
|
|
|
|
|
|
|
class State
|
|
|
|
{
|
2012-05-19 13:14:04 +04:00
|
|
|
public :
|
2012-05-19 14:03:02 +04:00
|
|
|
typedef ResourceTree::iterator iterator ;
|
2012-05-19 13:14:04 +04:00
|
|
|
|
2012-05-16 18:35:22 +04:00
|
|
|
public :
|
2017-03-19 19:54:03 +03:00
|
|
|
explicit State( const fs::path& root, const Val& options ) ;
|
2012-06-10 12:18:21 +04:00
|
|
|
~State() ;
|
2012-05-16 18:35:22 +04:00
|
|
|
|
2012-05-19 21:44:46 +04:00
|
|
|
void FromLocal( const fs::path& p ) ;
|
|
|
|
void FromRemote( const Entry& e ) ;
|
2012-05-17 20:37:11 +04:00
|
|
|
void ResolveEntry() ;
|
|
|
|
|
2017-03-19 19:54:03 +03:00
|
|
|
void Read() ;
|
|
|
|
void Write() ;
|
2012-05-16 18:35:22 +04:00
|
|
|
|
2012-05-24 13:47:26 +04:00
|
|
|
Resource* FindByHref( const std::string& href ) ;
|
|
|
|
Resource* FindByID( const std::string& id ) ;
|
2012-05-17 20:37:11 +04:00
|
|
|
|
2015-05-17 02:00:00 +03:00
|
|
|
void Sync( Syncer *syncer, const Val& options ) ;
|
2012-05-29 21:30:06 +04:00
|
|
|
|
2012-05-19 13:14:04 +04:00
|
|
|
iterator begin() ;
|
|
|
|
iterator end() ;
|
2012-05-27 18:49:49 +04:00
|
|
|
|
2012-06-03 19:58:28 +04:00
|
|
|
long ChangeStamp() const ;
|
|
|
|
void ChangeStamp( long cstamp ) ;
|
2015-11-10 12:54:47 +03:00
|
|
|
|
2012-05-17 20:37:11 +04:00
|
|
|
private :
|
2017-03-19 19:54:03 +03:00
|
|
|
bool ParseIgnoreFile( const char* buffer, int size ) ;
|
2016-01-01 02:27:21 +03:00
|
|
|
void FromLocal( const fs::path& p, Resource *folder, Val& tree ) ;
|
2012-06-10 17:03:32 +04:00
|
|
|
void FromChange( const Entry& e ) ;
|
2012-05-17 20:37:11 +04:00
|
|
|
bool Update( const Entry& e ) ;
|
|
|
|
std::size_t TryResolveEntry() ;
|
|
|
|
|
2015-09-25 13:01:26 +03:00
|
|
|
bool IsIgnore( const std::string& filename ) ;
|
2012-06-06 19:35:29 +04:00
|
|
|
|
2012-05-16 18:35:22 +04:00
|
|
|
private :
|
2017-03-19 19:54:03 +03:00
|
|
|
fs::path m_root ;
|
2012-05-29 21:30:06 +04:00
|
|
|
ResourceTree m_res ;
|
2014-07-23 14:47:16 +04:00
|
|
|
int m_cstamp ;
|
2015-12-12 16:59:02 +03:00
|
|
|
std::string m_ign ;
|
|
|
|
boost::regex m_ign_re ;
|
2016-01-01 02:27:21 +03:00
|
|
|
Val m_st ;
|
2016-01-02 15:05:37 +03:00
|
|
|
bool m_force ;
|
2016-05-11 15:56:59 +03:00
|
|
|
bool m_ign_changed ;
|
2012-05-18 04:52:11 +04:00
|
|
|
|
2016-01-03 16:24:55 +03:00
|
|
|
std::list<Entry> m_unresolved ;
|
2012-05-16 18:35:22 +04:00
|
|
|
} ;
|
|
|
|
|
2015-05-17 16:54:04 +03:00
|
|
|
} // end of namespace gr
|