Skip to content

Commit 2e6d87c

Browse files
rename: exists methods
fileExists -> existsFile directoryExists -> existsDir Signed-off-by: nkomonen <[email protected]>
1 parent df79d9a commit 2e6d87c

File tree

8 files changed

+24
-24
lines changed

8 files changed

+24
-24
lines changed

src/amazonqFeatureDev/util/files.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,5 +133,5 @@ export async function prepareRepoData(
133133

134134
export async function getSourceCodePath(workspaceRoot: string, projectRoot: string) {
135135
const srcRoot = path.join(workspaceRoot, projectRoot)
136-
return (await fsCommon.directoryExists(srcRoot)) ? srcRoot : workspaceRoot
136+
return (await fsCommon.existsDir(srcRoot)) ? srcRoot : workspaceRoot
137137
}

src/codewhisperer/vue/backend.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export class CodeWhispererWebview extends VueWebview {
3939
const fileContent = name[1]
4040

4141
const localFilePath = this.getLocalFilePath(fileName)
42-
if ((await fsCommon.fileExists(localFilePath)) && this.isFileSaved) {
42+
if ((await fsCommon.existsFile(localFilePath)) && this.isFileSaved) {
4343
const fileUri = vscode.Uri.file(localFilePath)
4444
await vscode.workspace.openTextDocument(fileUri).then(async doc => {
4545
await vscode.window.showTextDocument(doc, vscode.ViewColumn.Active).then(editor => {

src/shared/filesystemUtilities.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export async function getDirSize(
5353

5454
async function downloadsDir(): Promise<string> {
5555
const downloadPath = path.join(os.homedir(), 'Downloads')
56-
if (await fsCommon.directoryExists(downloadPath)) {
56+
if (await fsCommon.existsDir(downloadPath)) {
5757
return downloadPath
5858
} else {
5959
return os.tmpdir()
@@ -204,14 +204,14 @@ export async function getNonexistentFilename(
204204
if (!name) {
205205
throw new Error(`name is empty`)
206206
}
207-
if (!(await fsCommon.directoryExists(dir))) {
207+
if (!(await fsCommon.existsDir(dir))) {
208208
throw new Error(`directory does not exist: ${dir}`)
209209
}
210210
for (let i = 0; true; i++) {
211211
const filename =
212212
i === 0 ? `${name}${suffix}` : `${name}-${i < max ? i : crypto.randomBytes(4).toString('hex')}${suffix}`
213213
const fullpath = path.join(dir, filename)
214-
if (!(await fsCommon.fileExists(fullpath)) || i >= max + 99) {
214+
if (!(await fsCommon.existsFile(fullpath)) || i >= max + 99) {
215215
return filename
216216
}
217217
}
@@ -278,7 +278,7 @@ export async function cloud9Findfile(dir: string, fileName: string): Promise<vsc
278278
if (filePath === path.join(dir, fileName)) {
279279
return [vscode.Uri.file(filePath)]
280280
}
281-
if (await fsCommon.directoryExists(filePath)) {
281+
if (await fsCommon.existsDir(filePath)) {
282282
subDirs.push(vscode.Uri.file(filePath))
283283
}
284284
}
@@ -306,7 +306,7 @@ export async function getDefaultDownloadPath(): Promise<string> {
306306

307307
export async function setDefaultDownloadPath(downloadPath: string) {
308308
try {
309-
if (await fsCommon.directoryExists(downloadPath)) {
309+
if (await fsCommon.existsDir(downloadPath)) {
310310
GlobalState.instance.tryUpdate('aws.downloadPath', downloadPath)
311311
} else {
312312
GlobalState.instance.tryUpdate('aws.downloadPath', path.dirname(downloadPath))

src/shared/logger/activation.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ async function createLogWatcher(logFile: vscode.Uri): Promise<vscode.Disposable>
178178
return { dispose: () => {} }
179179
}
180180

181-
const exists = await waitUntil(() => fsCommon.fileExists(logFile), { interval: 1000, timeout: 60000 })
181+
const exists = await waitUntil(() => fsCommon.existsFile(logFile), { interval: 1000, timeout: 60000 })
182182

183183
if (!exists) {
184184
getLogger().warn(`Log file ${logFile.path} does not exist!`)
@@ -195,7 +195,7 @@ async function createLogWatcher(logFile: vscode.Uri): Promise<vscode.Disposable>
195195
return
196196
}
197197
checking = true
198-
if (!(await fsCommon.fileExists(logFile))) {
198+
if (!(await fsCommon.existsFile(logFile))) {
199199
await vscode.window.showWarningMessage(
200200
localize('AWS.log.logFileMove', 'The log file for this session has been moved or deleted.')
201201
)

src/shared/telemetry/telemetryService.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ export class DefaultTelemetryService {
167167
* VSCode provides the URI of the folder, but it is not guaranteed to exist.
168168
*/
169169
private static async ensureGlobalStorageExists(context: ExtensionContext): Promise<void> {
170-
if (!fsCommon.fileExists(context.globalStorageUri)) {
170+
if (!fsCommon.existsFile(context.globalStorageUri)) {
171171
await fsCommon.mkdir(context.globalStorageUri)
172172
}
173173
}
@@ -289,7 +289,7 @@ export class DefaultTelemetryService {
289289

290290
private static async readEventsFromCache(cachePath: string): Promise<MetricDatum[]> {
291291
try {
292-
if ((await fsCommon.fileExists(cachePath)) === false) {
292+
if ((await fsCommon.existsFile(cachePath)) === false) {
293293
getLogger().info(`telemetry cache not found: '${cachePath}'`)
294294

295295
return []

src/srcShared/fs.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export class FileSystemCommon {
6969
async appendFile(path: Uri | string, content: Uint8Array | string): Promise<void> {
7070
path = FileSystemCommon.getUri(path)
7171

72-
const currentContent: Uint8Array = (await this.fileExists(path)) ? await this.readFile(path) : new Uint8Array(0)
72+
const currentContent: Uint8Array = (await this.existsFile(path)) ? await this.readFile(path) : new Uint8Array(0)
7373
const currentLength = currentContent.length
7474

7575
const newContent = FileSystemCommon.asArray(content)
@@ -93,11 +93,11 @@ export class FileSystemCommon {
9393
}
9494
}
9595

96-
async fileExists(path: Uri | string): Promise<boolean> {
96+
async existsFile(path: Uri | string): Promise<boolean> {
9797
return this.exists(path, vscode.FileType.File)
9898
}
9999

100-
async directoryExists(path: Uri | string): Promise<boolean> {
100+
async existsDir(path: Uri | string): Promise<boolean> {
101101
return this.exists(path, vscode.FileType.Directory)
102102
}
103103

src/test/credentials/ui/vue/show.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,8 @@ describe('Add Connection webview', function () {
174174
const projectRoot = Uri.joinPath(Uri.file(getProjectDir()), '..', '..')
175175
const marketplaceImagesRoot = Uri.joinPath(projectRoot, 'docs/marketplace/vscode')
176176

177-
assert(await fsCommon.fileExists(Uri.joinPath(marketplaceImagesRoot, 'CC_dev_env.gif')))
178-
assert(await fsCommon.fileExists(Uri.joinPath(marketplaceImagesRoot, 'awsExplorer.gif')))
179-
assert(await fsCommon.fileExists(Uri.joinPath(marketplaceImagesRoot, 'codewhispererChat.gif')))
177+
assert(await fsCommon.existsFile(Uri.joinPath(marketplaceImagesRoot, 'CC_dev_env.gif')))
178+
assert(await fsCommon.existsFile(Uri.joinPath(marketplaceImagesRoot, 'awsExplorer.gif')))
179+
assert(await fsCommon.existsFile(Uri.joinPath(marketplaceImagesRoot, 'codewhispererChat.gif')))
180180
})
181181
})

src/test/srcShared/fs.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -117,34 +117,34 @@ describe('FileSystem', function () {
117117
})
118118
})
119119

120-
describe('fileExists()', function () {
120+
describe('existsFile()', function () {
121121
it('returns true for an existing file', async function () {
122122
const filePath = await makeFile('test.txt')
123-
const existantFile = await fsCommon.fileExists(filePath)
123+
const existantFile = await fsCommon.existsFile(filePath)
124124
assert.strictEqual(existantFile, true)
125125
})
126126

127127
it('returns false for a non-existant file', async function () {
128-
const nonExistantFile = await fsCommon.fileExists(createTestPath('thisDoesNotExist.txt'))
128+
const nonExistantFile = await fsCommon.existsFile(createTestPath('thisDoesNotExist.txt'))
129129
assert.strictEqual(nonExistantFile, false)
130130
})
131131

132132
it('returns false when directory with same name exists', async function () {
133133
const directoryPath = await makeFolder('thisIsDirectory')
134-
const existantFile = await fsCommon.fileExists(directoryPath)
134+
const existantFile = await fsCommon.existsFile(directoryPath)
135135
assert.strictEqual(existantFile, false)
136136
})
137137
})
138138

139-
describe('directoryExists()', function () {
139+
describe('existsDir()', function () {
140140
it('returns true for an existing directory', async function () {
141141
const dirPath = await makeFolder('myDir')
142-
const existantDirectory = await fsCommon.directoryExists(dirPath)
142+
const existantDirectory = await fsCommon.existsDir(dirPath)
143143
assert.strictEqual(existantDirectory, true)
144144
})
145145

146146
it('returns false for a non-existant directory', async function () {
147-
const nonExistantDirectory = await fsCommon.directoryExists(createTestPath('thisDirDoesNotExist'))
147+
const nonExistantDirectory = await fsCommon.existsDir(createTestPath('thisDirDoesNotExist'))
148148
assert.strictEqual(nonExistantDirectory, false)
149149
})
150150
})

0 commit comments

Comments
 (0)