Skip to content

Commit 1c0b4e7

Browse files
committed
Create service/utils/file.js
Add a new utility module for file/directory tools. Currently it contains only the filesystem-name sanitization code that used to live in service/plugins/sftp.js (used when creating filesystem objects with names based on device names).
1 parent c4f3113 commit 1c0b4e7

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/service/utils/file.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// SPDX-FileCopyrightText: GSConnect Developers https://github.com/GSConnect
2+
//
3+
// SPDX-License-Identifier: GPL-2.0-or-later
4+
5+
6+
/**
7+
* Sanitize a name when creating as a directory (or symlink, etc.)
8+
*
9+
* Note: %name CANNOT be a full path, as all of its path separators
10+
* will be replaced as part of sanitization.
11+
*
12+
* @param {string} name - The name to sanitize
13+
* @returns {string} The sanitized name
14+
*/
15+
export function safe_dirname(name) {
16+
let safe_name = name.replace('/', '∕');
17+
if (safe_name === '.')
18+
safe_name = '·';
19+
else if (safe_name === '..')
20+
safe_name = '··';
21+
return safe_name;
22+
}

0 commit comments

Comments
 (0)