MCPcopy Index your code
hub / github.com/NativeScript/NativeScript / renameSync

Method renameSync

packages/core/file-system/index.ts:122–170  ·  view source on GitHub ↗
(newName: string, onError?: (error: any) => any)

Source from the content-addressed store, hash-verified

120 }
121
122 public renameSync(newName: string, onError?: (error: any) => any): void {
123 if (this._isKnown) {
124 if (onError) {
125 onError(new Error('Cannot rename known folder.'));
126 }
127
128 return;
129 }
130
131 const localError = function (error) {
132 if (onError) {
133 onError(error);
134 }
135
136 return null;
137 };
138
139 const fileAccess = getFileAccess();
140 // call rename for FileSystemAccess29
141 if ((<any>fileAccess).__skip) {
142 fileAccess.rename(this.path, newName, localError);
143 const fileInfo = getFileAccess().getFile(this.path, null);
144 if (fileInfo) {
145 this._name = fileInfo.name;
146 this._extension = fileInfo.extension;
147 }
148 return;
149 }
150
151 const parentFolder = this.parent;
152 if (!parentFolder) {
153 if (onError) {
154 onError(new Error('No parent folder.'));
155 }
156
157 return;
158 }
159
160 const path = parentFolder.path;
161 const newPath = fileAccess.joinPath(path, newName);
162
163 fileAccess.rename(this.path, newPath, localError);
164 this._path = newPath;
165 this._name = newName;
166
167 if (this instanceof File) {
168 this._extension = fileAccess.getFileExtension(newPath);
169 }
170 }
171
172 get name(): string {
173 return this._name;

Callers 4

renameMethod · 0.95
renameMethod · 0.45
renameAsyncMethod · 0.45
doWorkFunction · 0.45

Calls 6

onErrorFunction · 0.85
getFileAccessFunction · 0.85
renameMethod · 0.65
getFileMethod · 0.65
joinPathMethod · 0.65
getFileExtensionMethod · 0.65

Tested by

no test coverage detected