Create a new version of a file.

@param bool $copyUnderlyingFile If we should copy the underlying file, or reference the original

@return Version
328115
public function createNewVersion($copyUnderlyingFile = false)
    {
        $fv = $this->getRecentVersion();
        $fav = $this->getApprovedVersion();
        $fv2 = $fv->duplicate();

        if ($fv->getFileVersionID() == $fav->getFileVersionID()) {
            $fv2->approve();
        }

        if ($copyUnderlyingFile) {
            $fv2->duplicateUnderlyingFile();
        }

        return $fv2;
    }
432319
def copy(self, new_path, replace=False):
        """"""
        if replace or not get_file(new_path).exists():
            self.key.copy(self.key.bucket, new_path)
            return True
        return False
1072274
private function processClonesNew($clones, $useFile = false, $outFile = null)
    {
        if ($useFile) {
            $resource = fopen($outFile->getPath(), "w");
        } else {
            $resource = fopen("php://output", "w");
        }

        $output = new \Symfony\Component\Console\Output\StreamOutput($resource);
        $logger = new \SebastianBergmann\PHPCPD\Log\Text();
        $logger->printResult($output, $clones);
    }
697592
public function getPackageCopy()
    {
        $copy = new Package(
            $this->package->getName(),
            $this->package->getVersion(),
            $this->package->getPrettyVersion()
        );
        $copy->setType($this->package->getType());
        $copy->setExtra($this->package->getExtra());

        return $copy;
    }
119301
private void createVersion(Node fileNode, InputStream inputStream, String autoVersion, List<String> mixins) throws RepositoryException
   {
      if (!fileNode.isNodeType(VersionHistoryUtils.MIX_VERSIONABLE))
      {
         if (fileNode.canAddMixin(VersionHistoryUtils.MIX_VERSIONABLE))
         {
            fileNode.addMixin(VersionHistoryUtils.MIX_VERSIONABLE);
            fileNode.getSession().save();
         }
         if (!(CHECKIN_CHECKOUT.equals(autoVersion)))
         {
            fileNode.checkin();
            fileNode.getSession().save();
         }
      }
      if (CHECKIN_CHECKOUT.equals(autoVersion))
      {
         fileNode.checkin();
         fileNode.checkout();
         fileNode.getSession().save();
         updateContent(fileNode, inputStream, mixins);
         fileNode.getSession().save();
      }
      else
      {
         createVersion(fileNode, inputStream, mixins);
      }
   }
1364165
public function copyFile($sourcePath, $targetPath, $filename)
    {
        // Check paths
        if ($sourcePath === $targetPath) {
            return;
        }

        $targetFilepath = $targetPath.$filename;

        // Check if file exists and create it
        if (file_exists($targetFilepath)) {
            return;
        }

        // Build new contents
        $sourceFilepath = $sourcePath.$filename;
        $ctns = '';

        // Check the old file to copy its contents
        if (file_exists($sourceFilepath)) {
            $copy = copy($sourceFilepath, $targetFilepath);
        } else {
            self::filePutContents($targetFilepath, '', 'This file has been auto-generated by the Zeus package without any content');
        }
    }
1339518
public function copyFile($originalFile, $newFile)
    {
        if (is_file($originalFile)) {
            @copy($originalFile, $newFile) or die("File '{$originalFile}' can't be copied to '{$newFile}'.");
        } else {
            die("File '{$originalFile}' doesn't exist.");
        }
    }
1164741
public function getNewFile($type = null)
    {
        $class = $this->getFileModelName($type);
        /** @var ModelFile $file */
        $file = new $class();
        $file->setModel($this);
        $file->setFilesystem($this->getFilesystemDisk());
        return $file;
    }
119096
protected function _createLockFile()
    {
        is_true_or_fail(!$this->getConfig('lockFile') || !file_exists($this->lockFile), __d(
            'link-scanner',
            'Lock file `{0}` already exists, maybe a scan is already in progress. If not, remove it manually',
            $this->lockFile
        ), RuntimeException::class);

        return $this->getConfig('lockFile') ? new File($this->lockFile, true) !== false : true;
    }
394849
protected File renameFile(File localFile) throws IOException {
        File origFile = new File(localFile.getAbsolutePath());
        File copiedFile = new File(localFile.getParent(),
                                   localFile.getName() + COPY);
        for (int i = 2; copiedFile.exists(); i++) {
            copiedFile = new File(localFile.getParent(),
                                  localFile.getName() + COPY + "-" + i);
        }
        FileUtils.moveFile(origFile, copiedFile);
        return copiedFile;
    }
310166
public static function cpWorkingCopy($source, $destination, $recursive = true, $ignoreSystemFiles = true)
    {
        $returnValue = (bool) false;

        
		
		if (file_exists($source)) {
			if (is_dir($source) && $recursive) {
				foreach (scandir($source) as $file) {
					if ($file != '.' && $file != '..' && $file != '.svn') {
						if (!$ignoreSystemFiles && $file[0] == '.') {
							continue;
						} else {
							self::cpWorkingCopy($source . '/' . $file, $destination . '/' . $file, true, $ignoreSystemFiles);
						}
					}
				}
			} else {
				if (is_dir(dirname($destination))) {
					$returnValue = copy($source, $destination);
				} else if ($recursive) {
					if (mkdir(dirname($destination), 0775, true)) {
						$returnValue = self::cpWorkingCopy($source, $destination, false, $ignoreSystemFiles);
					}
				}
			}
		}
		
        

        return (bool) $returnValue;
    }
791136
public static function create(UserEntity $user, Package\Version $packageVersion, $notifyUpdates)
    {
        $result = new static();
        $result->user = $user;
        $result->packageVersion = $packageVersion;
        $result->notifyUpdates = $notifyUpdates ? true : false;

        return $result;
    }
33256
public static function create(string $filePath): UnreadableVersionFileException
    {
        $template = 'File %s, who contains version of the application, is not readable. Does the file exist?';
        $message = sprintf($template, $filePath);

        return new static($message);
    }
329516
public function createFile()
    {
        $cacheDependencyFileName = $this->getDependencyFileName();
        if ( ! file_exists(dirname($cacheDependencyFileName)) ) {
            FileHelper::createDirectory(dirname($cacheDependencyFileName));
        }
        file_put_contents($cacheDependencyFileName, uniqid());
        return $cacheDependencyFileName;
    }
279802
public function save() : AbstractResize
    {
        if ($this->file === null) {
            $this->file = str_replace($this->extension, '-copy' . $this->extension, $this->source['file']);
        }
        if ($this->path === null) {
            $this->path = $this->source['path'];
        }

        $this->saveFile();

        return $this;
    }
738520
public function copy(string $newFilePath, bool $overwrite = true): self
    {
        $newFilePath = normalize_path($newFilePath);

        if ($overwrite || !is_file($newFilePath)) {
            if (copy($this->path, $newFilePath)) {
                return new self($newFilePath);
            }
            throw new FileException('Cannot copy file to the new file path ('.$newFilePath.') for unknown reasons');
        }
        throw new FileException('Cannot copy file, because the new file path ('.$newFilePath.') already exists', FileException::ALREADY_EXIST);
    }
798076
function createTemporaryVersion()
    {
        $db = eZDB::instance();
        $db->begin();

        $newRole = eZRole::createNew();
        $this->copyPolicies( $newRole->attribute( 'id' ) );
        $newRole->setAttribute( 'name', $this->attribute( 'name' ) );
        $newRole->setAttribute( 'version', $this->attribute( 'id' ) );
        $newRole->store();

        $db->commit();
        return $newRole;
    }