def test_file_to_metadata_path_case_complex(self):
      # Ensure the symlink dest is saved in the right path case. This includes 2
      # layers of symlinks.
      basedir = os.path.join(self.cwd, 'basebir')
      os.mkdir(basedir)

      linkeddir2 = os.path.join(self.cwd, 'linkeddir2')
      os.mkdir(linkeddir2)

      linkeddir1 = os.path.join(basedir, 'linkeddir1')
      os.symlink('../linkedDir2', linkeddir1)

      subsymlinkdir = os.path.join(basedir, 'symlinkdir')
      os.symlink('linkedDir1', subsymlinkdir)

      actual = isolated_format.file_to_metadata(
          unicode(subsymlinkdir.upper()), {}, True, ALGO)
      expected = {
        'l': u'linkeddir1', 't': int(os.stat(subsymlinkdir).st_mtime),
      }
      self.assertEqual(expected, actual)

      actual = isolated_format.file_to_metadata(
          unicode(linkeddir1.upper()), {}, True, ALGO)
      expected = {
        'l': u'../linkeddir2', 't': int(os.stat(linkeddir1).st_mtime),
      }
      self.assertEqual(expected, actual)
        def test_file_to_metadata_path_case_complex(self):
            # Ensure the symlink dest is saved in the right path case. This includes 2
            # layers of symlinks.
            basedir = os.path.join(self.cwd, 'basebir')
            os.mkdir(basedir)

            linkeddir2 = os.path.join(self.cwd, 'linkeddir2')
            os.mkdir(linkeddir2)

            linkeddir1 = os.path.join(basedir, 'linkeddir1')
            os.symlink('../linkedDir2', linkeddir1)

            subsymlinkdir = os.path.join(basedir, 'symlinkdir')
            os.symlink('linkedDir1', subsymlinkdir)

            actual = isolated_format.file_to_metadata(
                unicode(subsymlinkdir.upper()), {}, True, ALGO)
            expected = {
                'l': u'linkeddir1',
                't': int(os.stat(subsymlinkdir).st_mtime),
            }
            self.assertEqual(expected, actual)

            actual = isolated_format.file_to_metadata(
                unicode(linkeddir1.upper()), {}, True, ALGO)
            expected = {
                'l': u'../linkeddir2',
                't': int(os.stat(linkeddir1).st_mtime),
            }
            self.assertEqual(expected, actual)
Example #3
0
        def test_file_to_metadata_path_case_collapse(self):
            # Ensure setting the collapse_symlink option doesn't include the symlinks
            basedir = os.path.join(self.cwd, 'basedir')
            os.mkdir(basedir)
            subdir = os.path.join(basedir, 'subdir')
            os.mkdir(subdir)
            linkdir = os.path.join(basedir, 'linkdir')
            os.mkdir(linkdir)

            foo_file = os.path.join(subdir, 'Foo.txt')
            open(foo_file, 'w').close()
            sym_file = os.path.join(basedir, 'linkdir', 'Sym.txt')
            os.symlink('../subdir/Foo.txt', sym_file)

            actual = isolated_format.file_to_metadata(sym_file, {}, True, ALGO,
                                                      True)

            expected = {
                # SHA-1 of empty string
                'h': 'da39a3ee5e6b4b0d3255bfef95601890afd80709',
                'm': 288,
                's': 0,
                't': int(round(os.stat(foo_file).st_mtime)),
            }
            self.assertEqual(expected, actual)
 def test_file_to_metadata_path_case_simple(self):
     # Ensure the symlink dest is saved in the right path case.
     subdir = os.path.join(self.cwd, u'subdir')
     fs.mkdir(subdir)
     linkdir = os.path.join(self.cwd, u'linkdir')
     fs.symlink('subDir', linkdir)
     actual = isolated_format.file_to_metadata(linkdir.upper(), False)
     self.assertEqual({'l': u'subdir'}, actual)
 def test_file_to_metadata_path_case_simple(self):
     # Ensure the symlink dest is saved in the right path case.
     subdir = os.path.join(self.cwd, 'subdir')
     os.mkdir(subdir)
     linkdir = os.path.join(self.cwd, 'linkdir')
     os.symlink('subDir', linkdir)
     actual = isolated_format.file_to_metadata(unicode(linkdir.upper()),
                                               {}, True, ALGO)
     expected = {'l': u'subdir', 't': int(os.stat(linkdir).st_mtime)}
     self.assertEqual(expected, actual)
 def test_file_to_metadata_path_case_simple(self):
   # Ensure the symlink dest is saved in the right path case.
   subdir = os.path.join(self.cwd, 'subdir')
   os.mkdir(subdir)
   linkdir = os.path.join(self.cwd, 'linkdir')
   os.symlink('subDir', linkdir)
   actual = isolated_format.file_to_metadata(
       unicode(linkdir.upper()), {}, True, ALGO)
   expected = {'l': u'subdir', 't': int(os.stat(linkdir).st_mtime)}
   self.assertEqual(expected, actual)
Example #7
0
        def test_file_to_metadata_path_case_complex(self):
            # Ensure the symlink dest is saved in the right path case. This includes 2
            # layers of symlinks.
            basedir = os.path.join(self.cwd, u'basebir')
            fs.mkdir(basedir)

            linkeddir2 = os.path.join(self.cwd, u'linkeddir2')
            fs.mkdir(linkeddir2)

            linkeddir1 = os.path.join(basedir, u'linkeddir1')
            fs.symlink('../linkedDir2', linkeddir1)

            subsymlinkdir = os.path.join(basedir, u'symlinkdir')
            fs.symlink('linkedDir1', subsymlinkdir)

            actual = isolated_format.file_to_metadata(subsymlinkdir.upper(),
                                                      True, False)
            self.assertEqual({'l': u'linkeddir1'}, actual)

            actual = isolated_format.file_to_metadata(linkeddir1.upper(), True,
                                                      False)
            self.assertEqual({'l': u'../linkeddir2'}, actual)
Example #8
0
    def files_to_metadata(self, subdir):
        """Updates self.saved_state.files with the files' mode and hash.

    If |subdir| is specified, filters to a subdirectory. The resulting .isolated
    file is tainted.

    See isolated_format.file_to_metadata() for more information.
    """
        for infile in sorted(self.saved_state.files):
            if subdir and not infile.startswith(subdir):
                self.saved_state.files.pop(infile)
            else:
                filepath = os.path.join(self.root_dir, infile)
                self.saved_state.files[infile] = isolated_format.file_to_metadata(
                    filepath, self.saved_state.files[infile], self.saved_state.read_only, self.saved_state.algo
                )
Example #9
0
    def files_to_metadata(self, subdir):
        """Updates self.saved_state.files with the files' mode and hash.

    If |subdir| is specified, filters to a subdirectory. The resulting .isolated
    file is tainted.

    See isolated_format.file_to_metadata() for more information.
    """
        for infile in sorted(self.saved_state.files):
            if subdir and not infile.startswith(subdir):
                self.saved_state.files.pop(infile)
            else:
                filepath = os.path.join(self.root_dir, infile)
                self.saved_state.files[
                    infile] = isolated_format.file_to_metadata(
                        filepath, self.saved_state.files[infile],
                        self.saved_state.read_only, self.saved_state.algo)
Example #10
0
  def files_to_metadata(self, subdir, collapse_symlinks):
    """Updates self.saved_state.files with the files' mode and hash.

    If |subdir| is specified, filters to a subdirectory. The resulting .isolated
    file is tainted.

    See isolated_format.file_to_metadata() for more information.
    """
    for infile in sorted(self.saved_state.files):
      if subdir and not infile.startswith(subdir):
        self.saved_state.files.pop(infile)
      else:
        filepath = os.path.join(self.root_dir, infile)
        # This code used to try to reuse the previous data if possible in
        # saved_state. This performance optimization is not done anymore. This
        # code is going away soon and shouldn't be used in new code.
        meta = isolated_format.file_to_metadata(
            filepath,
            collapse_symlinks)
        if 'l' not in meta:
          meta['h'] = isolated_format.hash_file(filepath, self.saved_state.algo)
        self.saved_state.files[infile] = meta
Example #11
0
        def test_file_to_metadata_path_case_collapse(self):
            # Ensure setting the collapse_symlink option doesn't include the symlinks
            basedir = os.path.join(self.cwd, u'basedir')
            fs.mkdir(basedir)
            subdir = os.path.join(basedir, u'subdir')
            fs.mkdir(subdir)
            linkdir = os.path.join(basedir, u'linkdir')
            fs.mkdir(linkdir)

            foo_file = os.path.join(subdir, u'Foo.txt')
            fs.open(foo_file, 'w').close()
            sym_file = os.path.join(basedir, u'linkdir', u'Sym.txt')
            fs.symlink('../subdir/Foo.txt', sym_file)

            actual = isolated_format.file_to_metadata(sym_file, True, True)
            actual['h'] = isolated_format.hash_file(sym_file, ALGO)
            expected = {
                # SHA-1 of empty string
                'h': 'da39a3ee5e6b4b0d3255bfef95601890afd80709',
                'm': 256,
                's': 0,
            }
            self.assertEqual(expected, actual)