def tearDown(self):
   for dirpath, dirnames, filenames in os.walk(self.tempdir, topdown=True):
     for filename in filenames:
       run_isolated.set_read_only(os.path.join(dirpath, filename), False)
     for dirname in dirnames:
       run_isolated.set_read_only(os.path.join(dirpath, dirname), False)
   shutil.rmtree(self.tempdir)
   super(RunIsolatedTest, self).tearDown()
 def tearDown(self):
   for dirpath, dirnames, filenames in os.walk(self.tempdir, topdown=True):
     for filename in filenames:
       run_isolated.set_read_only(os.path.join(dirpath, filename), False)
     for dirname in dirnames:
       run_isolated.set_read_only(os.path.join(dirpath, dirname), False)
   shutil.rmtree(self.tempdir)
   super(RunIsolatedTest, self).tearDown()
 def test_hard_link_mode(self):
   # Creates a hard link, see if the file mode changed on the node or the
   # directory entry.
   dir_foo = os.path.join(self.tempdir, 'foo')
   file_bar = os.path.join(dir_foo, 'bar')
   file_link = os.path.join(dir_foo, 'link')
   os.mkdir(dir_foo, 0777)
   write_content(file_bar, 'bar')
   run_isolated.hardlink(file_bar, file_link)
   self.assertFileMode(file_bar, 0100666)
   self.assertFileMode(file_link, 0100666)
   run_isolated.set_read_only(file_bar, True)
   self.assertMaskedFileMode(file_bar, 0100444)
   self.assertMaskedFileMode(file_link, 0100444)
 def test_delete_rd_rf(self):
   # Confirms that a RO file in a RO directory can't be deleted.
   dir_foo = os.path.join(self.tempdir, 'foo')
   file_bar = os.path.join(dir_foo, 'bar')
   os.mkdir(dir_foo, 0777)
   write_content(file_bar, 'bar')
   run_isolated.set_read_only(dir_foo, True)
   run_isolated.set_read_only(file_bar, True)
   self.assertMaskedFileMode(dir_foo, 040555)
   self.assertMaskedFileMode(file_bar, 0100444)
   with self.assertRaises(OSError):
     # It fails for different reason depending on the OS. See the test cases
     # above.
     os.remove(file_bar)
 def test_delete_wd_rf(self):
   # Confirms that a RO file in a RW directory can be deleted on non-Windows.
   dir_foo = os.path.join(self.tempdir, 'foo')
   file_bar = os.path.join(dir_foo, 'bar')
   os.mkdir(dir_foo, 0777)
   write_content(file_bar, 'bar')
   run_isolated.set_read_only(dir_foo, False)
   run_isolated.set_read_only(file_bar, True)
   self.assertFileMode(dir_foo, 040777)
   self.assertMaskedFileMode(file_bar, 0100444)
   if sys.platform == 'win32':
     # On Windows, a read-only file can't be deleted.
     with self.assertRaises(OSError):
       os.remove(file_bar)
   else:
     os.remove(file_bar)
Example #6
0
 def test_delete_wd_rf(self):
     # Confirms that a RO file in a RW directory can be deleted on non-Windows.
     dir_foo = os.path.join(self.tempdir, 'foo')
     file_bar = os.path.join(dir_foo, 'bar')
     os.mkdir(dir_foo, 0777)
     write_content(file_bar, 'bar')
     run_isolated.set_read_only(dir_foo, False)
     run_isolated.set_read_only(file_bar, True)
     self.assertFileMode(dir_foo, 040777)
     self.assertMaskedFileMode(file_bar, 0100444)
     if sys.platform == 'win32':
         # On Windows, a read-only file can't be deleted.
         with self.assertRaises(OSError):
             os.remove(file_bar)
     else:
         os.remove(file_bar)
 def test_delete_rd_wf(self):
   # Confirms that a Rw file in a RO directory can be deleted on Windows only.
   dir_foo = os.path.join(self.tempdir, 'foo')
   file_bar = os.path.join(dir_foo, 'bar')
   os.mkdir(dir_foo, 0777)
   write_content(file_bar, 'bar')
   run_isolated.set_read_only(dir_foo, True)
   run_isolated.set_read_only(file_bar, False)
   self.assertMaskedFileMode(dir_foo, 040555)
   self.assertFileMode(file_bar, 0100666)
   if sys.platform == 'win32':
     # A read-only directory has a convoluted meaning on Windows, it means that
     # the directory is "personalized". This is used as a signal by Windows
     # Explorer to tell it to look into the directory for desktop.ini.
     # See http://support.microsoft.com/kb/326549 for more details.
     # As such, it is important to not try to set the read-only bit on
     # directories on Windows since it has no effect other than trigger
     # Windows Explorer to look for desktop.ini, which is unnecessary.
     os.remove(file_bar)
   else:
     with self.assertRaises(OSError):
       os.remove(file_bar)