remove copyfile/linkfile from last sync

Change-Id: I490411bc234e184aa8adedee099ebd38dde08925
diff --git a/project.py b/project.py
index b973085..152bae0 100644
--- a/project.py
+++ b/project.py
@@ -1224,13 +1224,40 @@
   def PostRepoUpgrade(self):
     self._InitHooks()
 
+  def RemoveOldCopyAndLinkFiles(self, path = None):
+    old_copylink = []    
+    file_path = os.path.join(self.gitdir if not path else path, '.repo_copylink')
+    if os.path.exists(file_path):
+      fd = open(file_path, 'r')
+      try:
+        old_copylink = fd.read().split('\n')
+      finally:
+        fd.close()
+    for target in old_copylink:
+      if os.path.exists(target):
+        if IsTrace():
+          Trace('rm %s', target)
+        os.remove(target)
+
   def _CopyAndLinkFiles(self):
     if self.manifest.isGitcClient:
       return
+    self.RemoveOldCopyAndLinkFiles()
+    new_copylink = []
     for copyfile in self.copyfiles:
       copyfile._Copy()
+      new_copylink.append(copyfile.abs_dest)
     for linkfile in self.linkfiles:
       linkfile._Link()
+      new_copylink.append(linkfile.abs_dest)
+    file_path = os.path.join(self.gitdir, '.repo_copylink')
+    fd = open(file_path, 'w')
+    try:
+      fd.write('\n'.join(new_copylink))
+      fd.write('\n')
+    finally:
+      fd.close()
+
 
   def GetCommitRevisionId(self):
     """Get revisionId of a commit.
diff --git a/subcmds/sync.py b/subcmds/sync.py
index 7bbbe44..6c2f320 100644
--- a/subcmds/sync.py
+++ b/subcmds/sync.py
@@ -511,6 +511,7 @@
                 except OSError:
                   break
                 project_dir = os.path.dirname(project_dir)
+              project.RemoveOldCopyAndLinkFiles(os.path.join(self.manifest.repodir, 'projects', '%s.git' % path))
 
     new_project_paths.sort()
     fd = open(file_path, 'w')