/**
  * Test read-only specific behavior.
  */
 function testReadOnlyBehavior()
 {
     // Generate a test file
     $filename = $this->randomMachineName();
     $site_path = $this->container->get('site.path');
     $filepath = $site_path . '/files/' . $filename;
     file_put_contents($filepath, $filename);
     // Generate a read-only stream wrapper instance
     $uri = $this->scheme . '://' . $filename;
     file_stream_wrapper_get_instance_by_scheme($this->scheme);
     // Attempt to open a file in read/write mode
     $handle = @fopen($uri, 'r+');
     $this->assertFalse($handle, 'Unable to open a file for reading and writing with the read-only stream wrapper.');
     // Attempt to open a file in binary read mode
     $handle = fopen($uri, 'rb');
     $this->assertTrue($handle, 'Able to open a file for reading in binary mode with the read-only stream wrapper.');
     $this->assertTrue(fclose($handle), 'Able to close file opened in binary mode using the read_only stream wrapper.');
     // Attempt to open a file in text read mode
     $handle = fopen($uri, 'rt');
     $this->assertTrue($handle, 'Able to open a file for reading in text mode with the read-only stream wrapper.');
     $this->assertTrue(fclose($handle), 'Able to close file opened in text mode using the read_only stream wrapper.');
     // Attempt to open a file in read mode
     $handle = fopen($uri, 'r');
     $this->assertTrue($handle, 'Able to open a file for reading with the read-only stream wrapper.');
     // Attempt to change file permissions
     $this->assertFalse(@chmod($uri, 0777), 'Unable to change file permissions when using read-only stream wrapper.');
     // Attempt to acquire an exclusive lock for writing
     $this->assertFalse(@flock($handle, LOCK_EX | LOCK_NB), 'Unable to acquire an exclusive lock using the read-only stream wrapper.');
     // Attempt to obtain a shared lock
     $this->assertTrue(flock($handle, LOCK_SH | LOCK_NB), 'Able to acquire a shared lock using the read-only stream wrapper.');
     // Attempt to release a shared lock
     $this->assertTrue(flock($handle, LOCK_UN | LOCK_NB), 'Able to release a shared lock using the read-only stream wrapper.');
     // Attempt to truncate the file
     $this->assertFalse(@ftruncate($handle, 0), 'Unable to truncate using the read-only stream wrapper.');
     // Attempt to write to the file
     $this->assertFalse(@fwrite($handle, $this->randomMachineName()), 'Unable to write to file using the read-only stream wrapper.');
     // Attempt to flush output to the file
     $this->assertFalse(@fflush($handle), 'Unable to flush output to file using the read-only stream wrapper.');
     // Attempt to close the stream.  (Suppress errors, as fclose triggers fflush.)
     $this->assertTrue(fclose($handle), 'Able to close file using the read_only stream wrapper.');
     // Test the rename() function
     $this->assertFalse(@rename($uri, $this->scheme . '://newname.txt'), 'Unable to rename files using the read-only stream wrapper.');
     // Test the unlink() function
     $this->assertTrue(@drupal_unlink($uri), 'Able to unlink file using read-only stream wrapper.');
     $this->assertTrue(file_exists($filepath), 'Unlink File was not actually deleted.');
     // Test the mkdir() function by attempting to create a directory.
     $dirname = $this->randomMachineName();
     $dir = $site_path . '/files/' . $dirname;
     $readonlydir = $this->scheme . '://' . $dirname;
     $this->assertFalse(@drupal_mkdir($readonlydir, 0775, 0), 'Unable to create directory with read-only stream wrapper.');
     // Create a temporary directory for testing purposes
     $this->assertTrue(drupal_mkdir($dir), 'Test directory created.');
     // Test the rmdir() function by attempting to remove the directory.
     $this->assertFalse(@drupal_rmdir($readonlydir), 'Unable to delete directory with read-only stream wrapper.');
     // Remove the temporary directory.
     drupal_rmdir($dir);
 }
Ejemplo n.º 2
0
 /**
  * Implements Drupal\Core\FileTransfer\FileTransfer::removeDirectoryJailed().
  */
 protected function removeDirectoryJailed($directory)
 {
     if (!is_dir($directory)) {
         // Programmer error assertion, not something we expect users to see.
         throw new FileTransferException('removeDirectoryJailed() called with a path (%directory) that is not a directory.', NULL, array('%directory' => $directory));
     }
     foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($directory, \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::CHILD_FIRST) as $filename => $file) {
         if ($file->isDir()) {
             if (@(!drupal_rmdir($filename))) {
                 throw new FileTransferException('Cannot remove directory %directory.', NULL, array('%directory' => $filename));
             }
         } elseif ($file->isFile()) {
             if (@(!drupal_unlink($filename))) {
                 throw new FileTransferException('Cannot remove file %file.', NULL, array('%file' => $filename));
             }
         }
     }
     if (@(!drupal_rmdir($directory))) {
         throw new FileTransferException('Cannot remove directory %directory.', NULL, array('%directory' => $directory));
     }
 }
Ejemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 public function deleteAll($prefix = '')
 {
     $success = TRUE;
     $files = $this->listAll($prefix);
     foreach ($files as $name) {
         if (!$this->delete($name) && $success) {
             $success = FALSE;
         }
     }
     if ($success && $this->collection != StorageInterface::DEFAULT_COLLECTION) {
         // Remove empty directories.
         if (!(new \FilesystemIterator($this->getCollectionDirectory()))->valid()) {
             drupal_rmdir($this->getCollectionDirectory());
         }
     }
     return $success;
 }
Ejemplo n.º 4
0
 /**
  * Support for rmdir().
  *
  * @param string $uri
  *   A string containing the URI to the directory to delete.
  * @param int $options
  *   A bit mask of STREAM_REPORT_ERRORS.
  *
  * @return bool
  *   TRUE if directory was successfully removed.
  *
  * @see http://php.net/manual/streamwrapper.rmdir.php
  */
 public function rmdir($uri, $options)
 {
     $this->uri = $uri;
     if ($options & STREAM_REPORT_ERRORS) {
         return drupal_rmdir($this->getLocalPath());
     } else {
         return @drupal_rmdir($this->getLocalPath());
     }
 }
Ejemplo n.º 5
0
 public function deleteFolder($filedepot_folder_id)
 {
     /* Test for valid folder and admin permission one more time
      * We are going to override the permission test in the function filedepot_getRecursiveCatIDs()
      * and return all subfolders in case hidden folders exist for this user.
      * If this user has admin permission for parent -- then they should be able to delete it
      * and any subfolders.
      */
     if ($filedepot_folder_id > 0 and $this->checkPermission($filedepot_folder_id, 'admin')) {
         // Need to delete all files in the folder
         /* Build an array of all linked categories under this category the user has admin access to */
         $list = array();
         array_push($list, $filedepot_folder_id);
         // Passing in permission check over-ride as noted above to filedepot_getRecursiveCatIDs()
         $list = $this->getRecursiveCatIDs($list, $filedepot_folder_id, 'admin', TRUE);
         foreach ($list as $cid) {
             // Drupal will remove the file attachments automatically when folder node is deleted even if file usage is > 1
             $query = db_query("SELECT drupal_fid FROM {filedepot_files} WHERE cid=:cid", array(':cid' => $cid));
             while ($A = $query->fetchAssoc()) {
                 $file = file_load($A['drupal_fid']);
                 file_usage_delete($file, 'filedepot');
                 if (file_exists($file->uri)) {
                     file_delete($file);
                 }
             }
             $subfolder_nid = db_query("SELECT nid FROM {filedepot_categories} WHERE cid=:cid", array(':cid' => $cid))->fetchField();
             db_delete('filedepot_categories')->condition('cid', $cid)->execute();
             db_delete('filedepot_categories')->condition('cid', $cid)->execute();
             db_delete('filedepot_access')->condition('catid', $cid)->execute();
             db_delete('filedepot_recentfolders')->condition('cid', $cid)->execute();
             db_delete('filedepot_notifications')->condition('cid', $cid)->execute();
             db_delete('filedepot_filesubmissions')->condition('cid', $cid)->execute();
             // Call the drupal node delete now for the subfolder node
             //watchdog('filedepot',"Calling node_delete for node id: {$subfolder_nid}");
             node_delete($subfolder_nid);
             // Remove the physical directory
             $uri = $this->root_storage_path . $cid;
             if (file_exists($uri)) {
                 $ret = @unlink("{$uri}/.htaccess");
                 $ret = @unlink("{$uri}/submissions/.htaccess");
                 $ret = @drupal_rmdir("{$uri}/submissions");
                 $ret = @drupal_rmdir($uri);
             }
         }
         return TRUE;
     } else {
         return FALSE;
     }
 }
 /**
  * Cleanup files created during download().
  *
  * It is expected that $files is returned from download(). Also, be aware that
  * each parent directory in the hierarchy may be removed if there are no more
  * files left in that directory.
  *
  * @param [] $files
  *   Array of files as returned from download() method.
  */
 public static function cleanup(array $files)
 {
     foreach ($files as $file_path => $file_name) {
         // Handle managed files.
         if (count(file_load_multiple([], ['uri' => $file_path])) > 0) {
             $file_obj = new \stdClass();
             $file_obj->uri = $file_path;
             file_delete($file_obj);
         } else {
             file_unmanaged_delete($file_path);
         }
         // Remove all directories in the tree if the file was the last one in this
         // directory.
         $file_dir = dirname($file_path);
         while (count(file_scan_directory($file_dir, '/.*/')) === 0) {
             if (!is_dir($file_dir)) {
                 break;
             }
             drupal_rmdir($file_dir);
             $file_dir = dirname($file_dir);
         }
     }
 }
Ejemplo n.º 7
0
<?php

/**
 * @file
 * Adminimal Menu Update file 7100.
 */
// Define Adminimal Menu path.
$module_path = drupal_get_path('module', 'adminimal_admin_menu');
// Delete the "adminimal_admin_menu.js" file.
file_unmanaged_delete($module_path . '/adminimal_admin_menu.js');
// Empty the "slicknav" folder.
file_unmanaged_delete_recursive($module_path . '/slicknav');
// Delete the "slicknav" folder.
drupal_rmdir($module_path . '/slicknav');