Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
Marsaud Smb2
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nanahira
Marsaud Smb2
Commits
f76c541b
Commit
f76c541b
authored
Aug 07, 2018
by
Julien Fontanet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(rename): option to replace existing target
parent
36ec5866
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
8 deletions
+29
-8
README.md
README.md
+17
-1
lib/api/rename.js
lib/api/rename.js
+12
-7
No files found.
README.md
View file @
f76c541b
...
...
@@ -154,7 +154,7 @@ smb2Client.readFile('path\\to\\my\\file.txt', function(err, content) {
If no encoding is specified, then the raw buffer is returned.
> `smb2Client.rename ( oldPath, newPath, callback )`
> `smb2Client.rename ( oldPath, newPath,
[ options, ]
callback )`
Asynchronous
`rename(2)`
: rename a file.
...
...
@@ -169,6 +169,22 @@ smb2Client.rename(
);
```
Existing files are not replaced by default, you need to pass the
`replace: true`
option for this use case:
```
javascript
smb2Client
.
rename
(
'
path
\\
to
\\
my
\\
file.txt
'
,
'
path
\\
to
\\
existing
\\
file.txt
'
,
{
replace
:
true
}
function
(
err
)
{
if
(
err
)
throw
err
;
console
.
log
(
'
file has been renamed
'
);
}
);
```
> `smb2Client.rmdir ( path, callback )`
Asynchronous
`rmdir(2)`
: delete an empty directory.
...
...
lib/api/rename.js
View file @
f76c541b
...
...
@@ -15,7 +15,12 @@ var FILE_OPEN_IF = require('../structures/constants').FILE_OPEN_IF;
* - close the file
*
*/
module
.
exports
=
function
rename
(
oldPath
,
newPath
,
cb
)
{
module
.
exports
=
function
rename
(
oldPath
,
newPath
,
options
,
cb
)
{
if
(
typeof
options
==
'
function
'
)
{
cb
=
options
;
options
=
{};
}
var
connection
=
this
;
// SMB2 open the folder / file
...
...
@@ -30,21 +35,21 @@ module.exports = function rename(oldPath, newPath, cb) {
connection
,
function
(
err
,
file
)
{
if
(
err
)
cb
&&
cb
(
err
);
else
rename_
(
connection
,
file
,
newPath
,
cb
);
else
rename_
(
connection
,
file
,
newPath
,
options
,
cb
);
}
);
else
rename_
(
connection
,
file
,
newPath
,
cb
);
else
rename_
(
connection
,
file
,
newPath
,
options
,
cb
);
});
};
function
rename_
(
connection
,
file
,
newPath
,
cb
)
{
function
rename_
(
connection
,
file
,
newPath
,
options
,
cb
)
{
// SMB2 rename
SMB2Request
(
'
set_info
'
,
{
FileId
:
file
.
FileId
,
FileInfoClass
:
'
FileRenameInformation
'
,
Buffer
:
renameBuffer
(
newPath
),
Buffer
:
renameBuffer
(
newPath
,
options
),
},
connection
,
function
(
err
)
{
...
...
@@ -58,12 +63,12 @@ function rename_(connection, file, newPath, cb) {
);
}
function
renameBuffer
(
newPath
)
{
function
renameBuffer
(
newPath
,
options
)
{
var
filename
=
Buffer
.
from
(
newPath
,
'
ucs2
'
);
return
Buffer
.
concat
([
// ReplaceIfExists 1 byte
new
bigint
(
1
,
0
).
toBuffer
(),
new
bigint
(
1
,
options
.
replace
?
1
:
0
).
toBuffer
(),
// Reserved 7 bytes
new
bigint
(
7
,
0
).
toBuffer
(),
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment