Skip to content

Commit

Permalink
added our own nqp::unlink() op
Browse files Browse the repository at this point in the history
Which might be able to delete write-protected files on windows.
  • Loading branch information
FROGGS committed Sep 28, 2013
1 parent 0bf3998 commit 401ed62
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
12 changes: 1 addition & 11 deletions src/vm/parrot/QAST/Operations.nqp
Original file line number Diff line number Diff line change
Expand Up @@ -1689,17 +1689,7 @@ QAST::Operations.add_core_op('chmod', -> $qastcomp, $op {
$op[0],
$op[1]) );
});
QAST::Operations.add_core_op('unlink', -> $qastcomp, $op {
if +$op.list != 1 {
nqp::die("The 'unlink' op expects one operand");
}
$qastcomp.as_post(QAST::Op.new(
:op('callmethod'),
:name('unlink'),
QAST::VM.new( :pirop('new__Ps'),
QAST::SVal.new( :value('OS') ) ),
$op[0] ) );
});
QAST::Operations.add_core_pirop_mapping('unlink', 'nqp_delete_f', 'Is');
QAST::Operations.add_core_op('rmdir', -> $qastcomp, $op {
if +$op.list != 1 {
nqp::die("The 'rmdir' op expects one operand");
Expand Down
26 changes: 26 additions & 0 deletions src/vm/parrot/ops/nqp.ops
Original file line number Diff line number Diff line change
Expand Up @@ -3514,6 +3514,32 @@ inline op nqp_getlexrelcaller(out PMC, in PMC, in STR) :base_core {
$1 = result;
}

inline op nqp_delete_f(out INT, in STR) :base_core {
#ifdef WIN32
char* const filename = Parrot_str_to_platform_cstring(interp, $2);
DWORD attrs = GetFileAttributesA(filename);
INTVAL ret;

if (attrs == 0xFFFFFFFF) {
errno = ENOENT;
ret = -1;
}
else if (attrs & FILE_ATTRIBUTE_READONLY) {
(void)SetFileAttributesA(filename, attrs & ~FILE_ATTRIBUTE_READONLY);
$1 = unlink(filename);

This comment has been minimized.

Copy link
@BenGoldberg1

BenGoldberg1 Sep 29, 2013

I think this line should be "ret = ...", not "$1 = ..."

if (ret == -1)
(void)SetFileAttributesA(filename, attrs);
}
else
ret = unlink(filename);

$1 = ret;
#else
char* const filename = Parrot_str_to_platform_cstring(interp, $2);
$1 = unlink(filename);
#endif
}

inline op nqp_shell(out INT, in STR, in STR, in PMC) {
STRING *command = $2;
STRING *dir = $3;
Expand Down

0 comments on commit 401ed62

Please sign in to comment.