94 {
96
97 $dirname = dirname($this->relative_path);
98 if (!$this->fs->has($dirname)) {
99 $this->
log(
"FAILED: Sanitizing File Path: {$this->file_object->getFile()}. Message: Directory not found");
100
101 return false;
102 }
103 try {
104 $first_file = reset($this->fs->listContents($dirname));
105 }
catch (DirectoryNotFoundException
$e) {
106 $this->
log(
"FAILED AGAIN and AGAIN: Sanitizing File Path: {$this->file_object->getFile()}. Message: {$e->getMessage()}");
107
108 return false;
109 }
111 try {
113
114 if (!$this->fs->has($valid_filename)) {
115 $this->fs->rename($first_file->getPath(), $valid_filename);
116
117
118 $this->
log(
"Sanitized File Path: {$valid_filename}");
119 }
121
122 return true;
123 }
catch (Exception
$e) {
124 $this->
log(
"FAILED: Sanitizing File Path: {$this->file_object->getFile()}. Message: {$e->getMessage()}. Will try using native PHP");
125
126 try {
127
128 $scandir = scandir(dirname($this->absolute_path));
129 if (isset($scandir[2])) {
130 $first_file = $scandir[2];
131 if (is_file($first_file)) {
133 if (rename($first_file, $valid_filename)) {
135 $this->
log(
"Sanitized File Path: {$valid_filename}");
136 }
137 } else {
138 throw new Exception("is not a file: " . $first_file);
139 }
140 } else {
141 throw new Exception("no File found in " . dirname($this->absolute_path));
142 }
143 }
catch (Exception
$e) {
144 $this->
log(
"FAILED AGAIN: Sanitizing File Path: {$this->file_object->getFile()}. Message: {$e->getMessage()}");
145
146 try {
147 foreach (new DirectoryIterator(dirname($this->absolute_path)) as $item) {
148 if ($item->isDot()) {
149 continue;
150 }
151 if ($item->isFile()) {
153 if (rename($item->getPathname(), $valid_filename)) {
155 $this->
log(
"Sanitized File Path: {$valid_filename}");
156 }
157 break;
158 }
159 }
160 }
catch (Exception
$e) {
161 $this->
log(
"FAILED AGAIN and AGAIN: Sanitizing File Path: {$this->file_object->getFile()}. Message: {$e->getMessage()}");
162 }
163 }
164
165 return false;
166 }
167 }
168
169 return false;
170 }
171
172 return true;
173 }
saveNewNameForFileObject($valid_filename)
santitizeFilename($first_file)
Class FlySystemFileAccessTest.
Class ChatMainBarProvider \MainMenu\Provider.