#!/usr/bin/env python
# -*- Mode: Python; indent-tabs-mode: nil; tab-width: 2; coding: utf-8 -*-
#
# This file is part of Déjà Dup.
# For copyright information, see AUTHORS.
#
# Déjà Dup 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; either version 3 of the License, or
# (at your option) any later version.
#
# Déjà Dup 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 Déjà Dup.  If not, see <http://www.gnu.org/licenses/>.

import sys
import os
sys.path.insert(0, sys.path[0]+'/..')
import base
import ldtp

def test():
  base.setup()
  sourcedir = base.get_temp_name('source', True)
  os.system('cp -r %s/data/simple/* %s' % (base.srcdir, sourcedir))
  base.backup_simple(backend='file', includes=[sourcedir], add_srcdir=False)
  os.system('echo bar > %s/foo' % sourcedir)
  os.system('rm -f %s/one %s/two' % (sourcedir, sourcedir))
  base.backup_simple()
  os.system('echo 1 > %s/one' % sourcedir)
  base.backup_simple()

  files = ['one', 'two', 'three']
  os.system('rm -f %s' % ' '.join([sourcedir+'/'+f for f in files]))
  base.restore_missing(files, sourcedir)

  assert base.file_equals(sourcedir+'/one', '1\n')
  assert base.file_equals(sourcedir+'/two', 'two\n')
  assert base.file_equals(sourcedir+'/three', 'three\n')

base.run(test)
